AddGroup adds one or more command groups to this parent command.
Rest
...groups: Group[]Context returns underlying command context. If command was executed with ExecuteContext or the context was set with SetContext, the previously set context will be returned. Otherwise, nil is returned.
Notice that a call to Execute and ExecuteC will replace a nil context of a command with a context.Background, so a background context will be returned by Context after one of these functions has been called.
FlagErrorFunc returns either the function set by SetFlagErrorFunc for this command or a parent, or it returns a function which returns the original error.
FlagErrorFunc returns either the function set by SetFlagErrorFunc for this command or a parent, or it returns a function which returns the original error.
GetFlagCompletionFunc returns the completion function for the given flag of the command, if available.
GlobalNormalizationFunc returns the global normalization function or nil if it doesn't exist.
GlobalNormalizationFunc returns the global normalization function or nil if it doesn't exist.
HelpFunc returns either the function set by SetHelpFunc for this command or a parent, or it returns a function with default help behavior.
HelpFunc returns either the function set by SetHelpFunc for this command or a parent, or it returns a function with default help behavior.
InitDefaultCompletionCmd adds a default 'completion' command to c. This function will do nothing if any of the following is true: 1- the feature has been explicitly disabled by the program, 2- c has no subcommands (to avoid creating one), 3- c already has a 'completion' command provided by the program.
IsAdditionalHelpTopicCommand determines if a command is an additional help topic command; additional help topic command is determined by the fact that it is NOT runnable/hidden/deprecated, and has no sub commands that are runnable/hidden/deprecated. Concrete example: https://github.com/spf13/cobra/issues/393#issuecomment-282741924.
MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. The bash completion script will call the bash function f for the flag.
This will only work for bash completion. It is recommended to instead use c.RegisterFlagCompletionFunc(...) which allows to register a Go function which will work across all shells.
MarkZshCompPositionalArgumentFile only worked for zsh and its behavior was not consistent with Bash completion. It has therefore been disabled. Instead, when no other completion is specified, file completion is done by default for every argument. One can disable file completion on a per-argument basis by using ValidArgsFunction and ShellCompDirectiveNoFileComp. To achieve file extension filtering, one can use ValidArgsFunction and ShellCompDirectiveFilterFileExt.
Deprecated
Rest
...patterns: string[]MarkZshCompPositionalArgumentWords only worked for zsh. It has therefore been disabled. To achieve the same behavior across all shells, one can use ValidArgs (for the first argument only) or ValidArgsFunction for any argument (can include the first one also).
Deprecated
Rest
...words: string[]RegisterFlagCompletionFunc should be called to register a function to provide completion for a flag.
UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.
UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.
Aliases is an array of aliases that can be used instead of the first word in Use.
Annotations are key/value pairs that can be used by applications to identify or group commands or set special options.
ArgAliases is List of aliases for ValidArgs. These are not suggested to the user in the shell completion, but accepted if entered manually.
Expected arguments
BashCompletionFunction is custom bash functions used by the legacy bash autocompletion generator. For portability with other shells, it is recommended to instead use ValidArgsFunction
CompletionOptions is a set of options to control the handling of shell completion
Deprecated defines, if this command is deprecated and should print this string when used.
DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...") will be printed by generating docs for this command.
DisableFlagParsing disables the flag parsing. If this is true all flags will be passed to the command as arguments.
DisableFlagsInUseLine will disable the addition of [flags] to the usage line of a command when printing help or generating docs
DisableSuggestions disables the suggestions based on Levenshtein distance that go along with 'unknown command' messages.
Example is examples of how to use the command.
FParseErrWhitelist flag parse errors to be ignored
The group id under which this subcommand is grouped in the 'help' output of its parent.
Hidden defines, if this command is hidden and should NOT show up in the list of available commands.
Long is the long message shown in the 'help
The *Run functions are executed in the following order:
* PersistentPreRun()
* PreRun()
* Run()
* PostRun()
* PersistentPostRun()
All functions get the same args, the arguments after the command name. The *PreRun and *PostRun functions will only be executed if the Run function of the current command has been declared.
PersistentPreRun: children of this command will inherit and execute.
Short is the short description shown in the 'help' output.
SilenceErrors is an option to quiet errors down stream.
SilenceUsage is an option to silence usage when an error occurs.
SuggestFor is an array of command names for which this command will be suggested - similar to aliases but only suggests.
SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions. Must be > 0.
TraverseChildren parses flags on all parents before executing child command.
Use is the one-line usage message. Recommended syntax is as follows:
[ ] 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
ValidArgs is list of all valid non-flag arguments that are accepted in shell completions
ValidArgsFunction is an optional function that provides valid non-flag arguments for shell completion. It is a dynamic version of using ValidArgs. Only one of ValidArgs and ValidArgsFunction can be used for a command.
Version defines the version for this command. If this value is non-empty and the command does not define a "version" flag, a "version" boolean flag will be added to the command and, if specified, will print content of the "Version" variable. A shorthand "v" flag will also be added if the command does not define one.
Generated using TypeDoc
Command is just that, a command for your application. E.g. 'go run ...' - 'run' is the command. Cobra requires you to define the usage and description as part of your command definition to ensure usability.