Documentation ¶
Index ¶
- Constants
- func Eq(a interface{}, b interface{}) bool
- func Gt(a interface{}, b interface{}) bool
- type Command
- func (c *Command) AddCommand(childCmd ...*Command)
- func (c *Command) CommandPath() string
- func (c *Command) Commands() []*Command
- func (c *Command) ErrOrStderr() io.Writer
- func (c *Command) Execute() error
- func (c *Command) ExecuteC() (cmd *Command, err error)
- func (c *Command) Find(args []string) (*Command, []string, error)
- func (c *Command) Flags() *flag.FlagSet
- func (c *Command) GenBashCompletionFile(filename string) error
- func (c *Command) HasParent() bool
- func (c *Command) HasSubCommands() bool
- func (c *Command) Help() error
- func (c *Command) HelpFunc() func(*Command, []string)
- func (c *Command) HelpTemplate() string
- func (c *Command) InOrStdin() io.Reader
- func (c *Command) InitDefaultHelpCmd()
- func (c *Command) InitDefaultHelpFlag()
- func (c *Command) Name() string
- func (c *Command) OutOrStderr() io.Writer
- func (c *Command) OutOrStdout() io.Writer
- func (c *Command) Parent() *Command
- func (c *Command) ParseFlags(args []string) error
- func (c *Command) PersistentFlags() *flag.FlagSet
- func (c *Command) Print(i ...interface{})
- func (c *Command) PrintErr(i ...interface{})
- func (c *Command) PrintErrf(format string, i ...interface{})
- func (c *Command) PrintErrln(i ...interface{})
- func (c *Command) Printf(format string, i ...interface{})
- func (c *Command) Println(i ...interface{})
- func (c *Command) Root() *Command
- func (c *Command) Runnable() bool
- func (c *Command) SetArgs(args []string)
- func (c *Command) SetErr(newErr io.Writer)
- func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName)
- func (c *Command) SetOut(newOut io.Writer)
- func (c *Command) Usage() error
- func (c *Command) UsageFunc() (f func(*Command) error)
- func (c *Command) UsageString() string
- func (c *Command) UsageTemplate() string
- func (c *Command) VisitParents(fn func(*Command))
- type FParseErrWhitelist
- type PositionalArgs
- type ShellCompDirective
Constants ¶
const ( BashCompFilenameExt = "cobra_annotation_bash_completion_filename_extensions" BashCompCustom = "cobra_annotation_bash_completion_custom" BashCompOneRequiredFlag = "cobra_annotation_bash_completion_one_required_flag" BashCompSubdirsInDir = "cobra_annotation_bash_completion_subdirs_in_dir" )
Annotations for Bash completion.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Command ¶
type Command struct { // Use is the one-line usage message. // Recommended syntax is as follow: // [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required. // ... indicates that you can specify multiple values for the previous argument. // | indicates mutually exclusive information. You can use the argument to the left of the separator or the // argument to the right of the separator. You cannot use both arguments in a single use of the command. // { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are // optional, they are enclosed in brackets ([ ]). // Example: add [-F file | -D dir]... [-f format] profile Use string // Short is the short description shown in the 'help' output. Short string // Long is the long message shown in the 'help <this-command>' output. Long string // Aliases is an array of aliases that can be used instead of the first word in Use. Aliases []string // Hidden defines, if this command is hidden and should NOT show up in the list of available commands. Hidden bool // DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...") // will be printed by generating docs for this command. DisableAutoGenTag bool // ValidArgs is list of all valid non-flag arguments that are accepted in bash completions ValidArgs []string // ValidArgsFunction is an optional function that provides valid non-flag arguments for bash completion. // It is a dynamic version of using ValidArgs. // Only one of ValidArgs and ValidArgsFunction can be used for a command. ValidArgsFunction func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) // Run: Typically the actual work function. Most commands will only implement this. Run func(cmd *Command, args []string) // RunE: Run but returns an error. RunE func(cmd *Command, args []string) error DisableFlagParsing bool // SilenceUsage is an option to silence usage when an error occurs. // We didn't, however, implement it in this simplified version of cobra. // Just for compatibility with hugo. SilenceUsage bool // contains filtered or unexported fields }
func (*Command) AddCommand ¶
AddCommand adds one or more commands to this parent command.
func (*Command) CommandPath ¶
CommandPath returns the full path to this command.
func (*Command) ErrOrStderr ¶
ErrOrStderr returns output to stderr
func (*Command) Execute ¶
Execute uses the args (os.Args[1:] by default) and run through the command tree finding appropriate matches for commands and then corresponding flags.
func (*Command) Find ¶
Find the target command given the args and command tree Meant to be run on the highest node. Only searches down.
func (*Command) Flags ¶
Flags returns the complete FlagSet that applies to this command (local and persistent declared here and by all parents).
func (*Command) GenBashCompletionFile ¶
GenBashCompletionFile generates bash completion file.
func (*Command) HasSubCommands ¶
HasSubCommands determines if the command has children commands.
func (*Command) Help ¶
Help puts out the help for the command. Used when a user calls help [command]. Can be defined by user by overriding HelpFunc.
func (*Command) HelpFunc ¶
HelpFunc returns either the function set by SetHelpFunc for this command or a parent, or it returns a function with default help behavior.
func (*Command) HelpTemplate ¶
HelpTemplate return help template for the command.
func (*Command) InitDefaultHelpCmd ¶
func (c *Command) InitDefaultHelpCmd()
InitDefaultHelpCmd adds default help command to c. It is called automatically by executing the c or by calling help and usage. If c already has help command or c has no subcommands, it will do nothing.
func (*Command) InitDefaultHelpFlag ¶
func (c *Command) InitDefaultHelpFlag()
InitDefaultHelpFlag adds default help flag to c. It is called automatically by executing the c or by calling help and usage. If c already has help flag, it will do nothing.
func (*Command) OutOrStderr ¶
OutOrStderr returns output to stderr
func (*Command) OutOrStdout ¶
OutOrStdout returns output to stdout.
func (*Command) ParseFlags ¶
ParseFlags parses persistent flag tree and local flags.
func (*Command) PersistentFlags ¶
PersistentFlags returns the persistent FlagSet specifically set in the current command.
func (*Command) Print ¶
func (c *Command) Print(i ...interface{})
Print is a convenience method to Print to the defined output, fallback to Stderr if not set.
func (*Command) PrintErr ¶
func (c *Command) PrintErr(i ...interface{})
PrintErr is a convenience method to Print to the defined Err output, fallback to Stderr if not set.
func (*Command) PrintErrf ¶
PrintErrf is a convenience method to Printf to the defined Err output, fallback to Stderr if not set.
func (*Command) PrintErrln ¶
func (c *Command) PrintErrln(i ...interface{})
PrintErrln is a convenience method to Println to the defined Err output, fallback to Stderr if not set.
func (*Command) Printf ¶
Printf is a convenience method to Printf to the defined output, fallback to Stderr if not set.
func (*Command) Println ¶
func (c *Command) Println(i ...interface{})
Println is a convenience method to Println to the defined output, fallback to Stderr if not set.
func (*Command) SetGlobalNormalizationFunc ¶
func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName)
SetGlobalNormalizationFunc sets a normalization function to all flag sets and also to child commands. The user should not have a cyclic dependency on commands.
func (*Command) Usage ¶
Usage puts out the usage for the command. Used when a user provides invalid input. Can be defined by user by overriding UsageFunc.
func (*Command) UsageFunc ¶
UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.
func (*Command) UsageString ¶
UsageString returns usage string.
func (*Command) UsageTemplate ¶
UsageTemplate returns usage template for the command.
func (*Command) VisitParents ¶
VisitParents visits all parents of the command and invokes fn on each parent.
type FParseErrWhitelist ¶
type FParseErrWhitelist flag.ParseErrorsWhitelist
FParseErrWhitelist configures Flag parse errors to be ignored
type PositionalArgs ¶
type ShellCompDirective ¶
type ShellCompDirective int
ShellCompDirective is a bit map representing the different behaviors the shell can be instructed to have once completions have been provided.
const ( // ShellCompDirectiveError indicates an error occurred and completions should be ignored. ShellCompDirectiveError ShellCompDirective = 1 << iota // ShellCompDirectiveNoSpace indicates that the shell should not add a space // after the completion even if there is a single completion provided. ShellCompDirectiveNoSpace // ShellCompDirectiveNoFileComp indicates that the shell should not provide // file completion even when no completion is provided. // This currently does not work for zsh or bash < 4 ShellCompDirectiveNoFileComp // ShellCompDirectiveFilterFileExt indicates that the provided completions // should be used as file extension filters. // For flags, using Command.MarkFlagFilename() and Command.MarkPersistentFlagFilename() // is a shortcut to using this directive explicitly. The BashCompFilenameExt // annotation can also be used to obtain the same behavior for flags. ShellCompDirectiveFilterFileExt // ShellCompDirectiveFilterDirs indicates that only directory names should // be provided in file completion. To request directory names within another // directory, the returned completions should specify the directory within // which to search. The BashCompSubdirsInDir annotation can be used to // obtain the same behavior but only for flags. ShellCompDirectiveFilterDirs // ShellCompDirectiveDefault indicates to let the shell perform its default // behavior after completions have been provided. // This one must be last to avoid messing up the iota count. ShellCompDirectiveDefault ShellCompDirective = 0 )