Documentation
¶
Index ¶
- func Active(name string) bool
- func AddCommand(command *Command) error
- func CommandUsage() string
- func CommandUsages() string
- func CommandUsagesWrapped(cols int) string
- func FlagUsages() string
- func GetDescription() string
- func IsActive() bool
- func NewFlagSet(name string, errorHandling flag.ErrorHandling) *flag.FlagSet
- func Parse(arguments []string, flags *flag.FlagSet) error
- func Reset()
- type Command
- func Cmd(name string, usage string, flags *flag.FlagSet) (*Command, error)
- func Lookup(name string) *Command
- func NewCommand(name string, usage string, flags *flag.FlagSet) *Command
- func SetCallback(callback CommandCallback) *Command
- func SetDescription(description string) *Command
- func SetOutput(output io.Writer) *Command
- func SetUsageFunc(usageFunc UsageFunc) *Command
- func (c *Command) Active(name string) bool
- func (c *Command) AddCommand(command *Command) error
- func (c *Command) Cmd(name string, usage string, flags *flag.FlagSet) (*Command, error)
- func (c *Command) CommandUsage() string
- func (c *Command) CommandUsages() string
- func (c *Command) CommandUsagesWrapped(cols int) string
- func (c *Command) FlagUsages() string
- func (c *Command) FlagUsagesWrapped(cols int) string
- func (c *Command) GetDescription() string
- func (c *Command) GetName() string
- func (c *Command) GetUsage() string
- func (c *Command) IsActive() bool
- func (c *Command) IsDeprecated() bool
- func (c *Command) IsHidden() bool
- func (c *Command) Lookup(name string) *Command
- func (c *Command) MarkDeprecated() *Command
- func (c *Command) MarkHidden() *Command
- func (c *Command) Parse(arguments []string) error
- func (c *Command) SetCallback(callback CommandCallback) *Command
- func (c *Command) SetDescription(description string) *Command
- func (c *Command) SetOutput(output io.Writer) *Command
- func (c *Command) SetRecurseArguments() *Command
- func (c *Command) SetUsageFunc(usageFunc UsageFunc) *Command
- type CommandCallback
- type UsageFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Active ¶ added in v0.2.0
Active searches for a registered command by its name and reports its activation state. See IsActive.
func AddCommand ¶
AddCommand adds command to the global register. When a command with the same name already exists, the operation is cancelled and an error is returned.
func CommandUsage ¶ added in v0.2.0
func CommandUsage() string
CommandUsage returns a string containing the usage information for the application and all commands, including the application description if defined.
func CommandUsages ¶
func CommandUsages() string
CommandUsages returns a string containing the usage information for all commands defined for the application.
func CommandUsagesWrapped ¶ added in v0.3.0
CommandUsagesWrapped returns a string containing the usage information for all subcommands defined for this command. Wrapped to cols columns (0 for no wrapping).
func FlagUsages ¶ added in v0.2.0
func FlagUsages() string
FlagUsages returns a string containing the usage information for all flags defined for this command.
func GetDescription ¶ added in v0.2.0
func GetDescription() string
GetDescription returns the application description if set. See SetDescription.
func IsActive ¶
func IsActive() bool
IsActive reports whether the global command is active, i.e. Parse has been called.
func NewFlagSet ¶ added in v0.2.0
func NewFlagSet(name string, errorHandling flag.ErrorHandling) *flag.FlagSet
NewFlagSet creates a flag.FlagSet with ParseErrorsWhitelist.UnknownFlags enabled, which is required to process subcommands.
func Parse ¶
Parse parses the application command line arguments respecting the defined global command structure. Arguments for each command are parsed using pflag. The first argument is expected to be the application path. Use flag.NewFlagSet to create the flag.FlagSet for parsing top-level application flags.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
A Command represents a (sub)command with a set of defined flags.
func Cmd ¶
Cmd creates and adds a new command to the global register. When the command is added successfully, the Command value is returned. Else nil and an error is returned.
func Lookup ¶ added in v0.2.0
Lookup searches for a registered command by its name. If no matching command is found, nil is returned.
func NewCommand ¶
NewCommand creates a new Command object for use with AddCommand. A top-level command must have an empty name. Use flag.NewFlagSet to create the flag.FlagSet.
func SetCallback ¶ added in v0.4.0
func SetCallback(callback CommandCallback) *Command
SetCallback sets the global function which is executed at the end of the parsing process, when no callback is defined for the active command. The last active command (with or without a callback defined) is passed to the callback.
func SetDescription ¶
SetDescription defines a long description that is displayed on the generated help page. See CommandUsages.
func SetOutput ¶ added in v0.2.0
SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.
func SetUsageFunc ¶ added in v0.4.0
SetUsageFunc sets the function which prints the command usage when the --help flag is recognized during parsing. By default, it prints the output of CommandUsage which is roughly equivalent to fmt.Printf("%s\n%s\nCommands:\n%sFlags:\n%s", c.GetUsage(), c.GetDescription(), c.CommandUsages(), c.FlagUsages())
func (*Command) Active ¶ added in v0.2.0
Active searches for a registered subcommand by its name and reports its activation state. See IsActive.
func (*Command) AddCommand ¶
AddCommand adds command as a subcommand. When a command with the same name already exists, the operation is cancelled and an error is returned.
func (*Command) Cmd ¶
Cmd creates a new command and adds it as a subcommand. When the command is added successfully, the Command value is returned. Else nil and an error is returned.
func (*Command) CommandUsage ¶ added in v0.2.0
CommandUsage returns a string containing the usage information for this command and all subcommands, including the description for this command if defined.
func (*Command) CommandUsages ¶
CommandUsages returns a string containing the usage information for all subcommands defined for this command.
func (*Command) CommandUsagesWrapped ¶ added in v0.3.0
CommandUsagesWrapped returns a string containing the usage information for all subcommands defined for this command. Wrapped to cols columns (0 for no wrapping).
func (*Command) FlagUsages ¶ added in v0.2.0
FlagUsages returns a string containing the usage information for all flags defined for this command.
func (*Command) FlagUsagesWrapped ¶ added in v0.3.0
FlagUsagesWrapped returns a string containing the usage information for all flags defined for this command. Wrapped to cols columns (0 for no wrapping).
func (*Command) GetDescription ¶ added in v0.2.0
GetDescription returns the command description if set. See Command.SetDescription.
func (*Command) IsActive ¶
IsActive reports whether the command is active, i.e. it was supplied to the command line when calling Parse.
func (*Command) IsDeprecated ¶ added in v0.2.0
IsDeprecated reports whether the command is marked as deprecated, i.e. it is not listed in help and usage messages and a warning is displayed on its help message.
func (*Command) IsHidden ¶ added in v0.2.0
IsHidden reports whether the command is marked as hidden, i.e. it is not listed in help and usage messages.
func (*Command) Lookup ¶ added in v0.2.0
Lookup searches for a registered subcommand by its name. If no matching command is found, nil is returned.
func (*Command) MarkDeprecated ¶ added in v0.2.0
MarkDeprecated indicates that the command is deprecated. It will continue to function but will not show up in help or usage messages.
func (*Command) MarkHidden ¶ added in v0.2.0
MarkHidden sets the command to 'hidden'. It will continue to function but will not show up in help or usage messages.
func (*Command) Parse ¶
Parse parses the command line arguments respecting the defined command structure. Arguments for each command are parsed using pflag.
func (*Command) SetCallback ¶ added in v0.4.0
func (c *Command) SetCallback(callback CommandCallback) *Command
SetCallback sets the function which is executed when the command is the last active command with a callback defined at the end of the parsing process. The last active command (with or without a callback defined) is passed to the callback.
func (*Command) SetDescription ¶
SetDescription defines a long description that is displayed on the generated help page. See CommandUsages.
func (*Command) SetOutput ¶ added in v0.2.0
SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.
func (*Command) SetRecurseArguments ¶ added in v0.5.0
SetRecurseArguments enables recursive parsing of arguments using the parent commands of this command.
func (*Command) SetUsageFunc ¶ added in v0.4.0
SetUsageFunc sets the function which prints the command usage when the --help flag is recognized during parsing. By default, it prints the output of CommandUsage which is roughly equivalent to fmt.Printf("%s\n%s\nCommands:\n%sFlags:\n%s", c.GetUsage(), c.GetDescription(), c.CommandUsages(), c.FlagUsages())