Documentation
¶
Index ¶
- type Command
- func (c *Command) AddCommand(children ...*Command)
- func (c *Command) AddCompletionCommand()
- func (c *Command) BoolVarP(p *bool, long, short string, value bool, usage string)
- func (c *Command) Command(name string) *Command
- func (c *Command) Commands() []*Command
- func (c *Command) Context() context.Context
- func (c *Command) ErrWriter() io.Writer
- func (c *Command) Execute() error
- func (c *Command) ExecuteContext(ctx context.Context, args []string) error
- func (c *Command) Flags() *flag.FlagSet
- func (c *Command) GenBashCompletion(w io.Writer) error
- func (c *Command) GenFishCompletion(w io.Writer) error
- func (c *Command) GenPowerShellCompletion(w io.Writer) error
- func (c *Command) GenZshCompletion(w io.Writer) error
- func (c *Command) Help()
- func (c *Command) InReader() io.Reader
- func (c *Command) IntVarP(p *int, long, short string, value int, usage string)
- func (c *Command) Name() string
- func (c *Command) OutWriter() io.Writer
- func (c *Command) Parent() *Command
- func (c *Command) PersistentFlags() *flag.FlagSet
- func (c *Command) SetContext(ctx context.Context)
- func (c *Command) SetErrWriter(w io.Writer)
- func (c *Command) SetInReader(r io.Reader)
- func (c *Command) SetOutWriter(w io.Writer)
- func (c *Command) StringVarP(p *string, long, short string, value string, usage string)
- type Group
- type PositionalArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Use is the one-line usage message. Recommended syntax: "cmd [flags] [arg...]"
Use string
// Short is the short description shown in help.
Short string
// Long is the long message shown in help.
Long string
// Example is an optional field to show usage examples.
Example string
// Deprecated marks this command as deprecated and prints the given message.
Deprecated string
// Version defines the version for this command. If set on the root command,
// a --version flag will be added automatically.
Version string
// Annotations are arbitrary key-value pairs attached to the command.
Annotations map[string]string
// Run is the function that executes the command. If nil, the command is considered a group.
// The command's context is available via cmd.Context().
Run func(cmd *Command, args []string) error
// Aliases is a list of alternative names for this command.
Aliases []string
// SuggestFor is a list of command names for which this command will be suggested.
SuggestFor []string
// Args defines validation for positional arguments.
Args PositionalArgs
// ValidArgs is a list of valid positional arguments for shell completion.
ValidArgs []string
// ArgAliases is a list of aliases for ValidArgs (accepted but not suggested).
ArgAliases []string
// GroupID identifies the command group in help output.
GroupID string
// CommandGroups is a list of groups for subcommands (used on parent).
CommandGroups []*Group
// Hidden, if true, hides the command from help output.
Hidden bool
// SilenceErrors, if true, suppresses automatic error printing.
SilenceErrors bool
// SilenceUsage, if true, suppresses usage printing when an error occurs.
SilenceUsage bool
// DisableFlagParsing disables flag parsing entirely; all arguments are treated as positional.
DisableFlagParsing bool
// DisableSuggestions disables command name suggestions for unknown commands.
DisableSuggestions bool
// SuggestionsMinimumDistance sets the minimum Levenshtein distance for suggestions.
SuggestionsMinimumDistance int
// TraverseChildren, if true, parses flags on all parents before executing child commands.
TraverseChildren bool
// PersistentPreRunE is executed before any children commands (in parent order).
PersistentPreRunE func(cmd *Command, args []string) error
// PreRunE is executed before the command's Run function.
PreRunE func(cmd *Command, args []string) error
// PostRunE is executed after the command's Run function.
PostRunE func(cmd *Command, args []string) error
// PersistentPostRunE is executed after all children commands (in child order).
PersistentPostRunE func(cmd *Command, args []string) error
// contains filtered or unexported fields
}
Command represents a CLI command with subcommands, flags, and an action.
func NewCommand ¶
NewCommand creates a new command with the given name and description.
func (*Command) AddCommand ¶
AddCommand adds one or more subcommands to this command.
func (*Command) AddCompletionCommand ¶
func (c *Command) AddCompletionCommand()
AddCompletionCommand adds the __complete and __completeNoDesc subcommands to the root command. This is automatically called for root commands, but can be called manually if needed.
func (*Command) Command ¶
Command returns the subcommand with the given name or alias, or nil if not found.
func (*Command) Context ¶
Context returns the context associated with this command. It is set by ExecuteContext or SetContext.
func (*Command) Execute ¶
Execute runs the command with the given arguments (usually os.Args[1:]). It uses context.Background().
func (*Command) ExecuteContext ¶
ExecuteContext runs the command with a context and arguments. It sets the command's context before execution.
func (*Command) GenBashCompletion ¶
GenBashCompletion writes bash completion script to the given writer.
func (*Command) GenFishCompletion ¶
GenFishCompletion writes fish completion script to the given writer.
func (*Command) GenPowerShellCompletion ¶
GenPowerShellCompletion writes PowerShell completion script to the given writer.
func (*Command) GenZshCompletion ¶
GenZshCompletion writes zsh completion script to the given writer.
func (*Command) IntVarP ¶
IntVarP defines an integer flag with both long and short names. It sets the variable p to the value given on the command line.
func (*Command) PersistentFlags ¶
PersistentFlags returns the persistent flag set for this command.
func (*Command) SetContext ¶
SetContext sets the context for this command.
func (*Command) SetErrWriter ¶
SetErrWriter sets the error writer.
func (*Command) SetInReader ¶
SetInReader sets the input reader.
func (*Command) SetOutWriter ¶
SetOutWriter sets the output writer.
type PositionalArgs ¶
PositionalArgs defines a function to validate positional arguments.