Documentation
¶
Overview ¶
Package cli provides a thin CLI abstraction around the standard flag package. It is minimal, command-struct-oriented, and trades off "power" for flexibility and clarity at the caller level.
It pretends that Go's single dash (-flag) support doesn't exist, and renders helps with --.
Optional interface adherence can be asserted with a statement like
var _ interface {
cli.Command
cli.FlaggedCommand
cli.ParentCommand
} = new(rootCmd)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Command ¶
type Command interface {
// Spec returns metadata about the command.
Spec() CommandSpec
// Run invokes the command's main routine with parsed flags.
Run(fl *flag.FlagSet)
}
Command describes a command or subcommand.
type CommandSpec ¶
type CommandSpec struct {
// Name is the name of the command.
// It should be the leaf name of the entire command. E.g `run` for the full
// command `sail run`.
Name string
// Usage is the command's usage string.
// E.g "[flags] <path>"
Usage string
// Desc is the description of the command.
// The first line is used as an abbreviated description.
Desc string
// Hidden indicates that this command should not show up in it's parent's
// subcommand help.
Hidden bool
}
CommandSpec describes a Command's usage.
It should not list flags.
func (CommandSpec) ShortDesc ¶
func (c CommandSpec) ShortDesc() string
ShortDesc returns the first line of Desc.
type FlaggedCommand ¶
type FlaggedCommand interface {
// RegisterFlags lets the command register flags which be sent to Handle.
RegisterFlags(fl *flag.FlagSet)
}
FlaggedCommand is an optional interface for commands that have flags.
type ParentCommand ¶
type ParentCommand interface {
Subcommands() []Command
}
ParentCommand is an optional interface for commands that have subcommands.
A ParentCommand may pass itself into children as it creates them in order to pass high-level configuration and state.