Skip to content
Myr

Fix docs for Command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 6bfe2ba · Browse files · 1 file+68 added−53 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+68 added−53 removed

  • other:+68 added−53 removed

1 file+68 added−53 removed

modified:command.go+68 added-53 removed
26 unmodified lines
27 flag "github.com/spf13/pflag"28)2930// Command is just that, a command for your application.31// eg. 'go run' ... 'run' is the command. Cobra requires31// E.g. 'go run ...' - 'run' is the command. Cobra requires32// you to define the usage and description as part of your command33// definition to ensure usability.34type Command struct {35 // Name is the command name, usually the executable's name.35 // name is the command name, usually the executable's name.36 name string37 // The one-line usage message.37 // Use is the one-line usage message.38 Use string39 // An array of aliases that can be used instead of the first word in Use.39 // Aliases is an array of aliases that can be used instead of the first word in Use.40 Aliases []string41 // An array of command names for which this command will be suggested - similar to aliases but only suggests.41 // SuggestFor is an array of command names for which this command will be suggested -42 // similar to aliases but only suggests.43 SuggestFor []string43 // The short description shown in the 'help' output.44 // Short is the short description shown in the 'help' output.45 Short string45 // The long message shown in the 'help <this-command>' output.46 // Long is the long message shown in the 'help <this-command>' output.47 Long string47 // Examples of how to use the command48 // Example is examples of how to use the command.49 Example string49 // List of all valid non-flag arguments that are accepted in bash completions50 // ValidArgs is list of all valid non-flag arguments that are accepted in bash completions51 ValidArgs []string51 // List of aliases for ValidArgs. These are not suggested to the user in the bash52 // completion, but accepted if entered manually.52 // ArgAliases is List of aliases for ValidArgs.53 // These are not suggested to the user in the bash completion,54 // but accepted if entered manually.55 ArgAliases []string54 // Custom functions used by the bash autocompletion generator56 // BashCompletionFunction is custom functions used by the bash autocompletion generator.57 BashCompletionFunction string56 // Is this command deprecated and should print this string when used?58 // Deprecated defines, if this command deprecated and should print this string when used.59 Deprecated string58 // Is this command hidden and should NOT show up in the list of available commands?60 // Hidden defines, if this command hidden and should NOT show up in the list of available commands.61 Hidden bool62 // Annotations are key/value pairs that can be used by applications to identify or61 // group commands63 // group commands.64 Annotations map[string]string63 // Full set of flags65 // flags is full set of flags.66 flags *flag.FlagSet65 // Set of flags childrens of this command will inherit67 // pflags contains persistent flags.68 pflags *flag.FlagSet67 // Flags that are declared specifically by this command (not inherited).69 // lflags contains local flags.70 lflags *flag.FlagSet69 // Inherited flags.71 // iflags contains inherited flags.72 iflags *flag.FlagSet71 // All persistent flags of cmd's parents.73 // parentsPflags is all persistent flags of cmd's parents.74 parentsPflags *flag.FlagSet73 // SilenceErrors is an option to quiet errors down stream75 // SilenceErrors is an option to quiet errors down stream.76 SilenceErrors bool77 // Silence Usage is an option to silence usage when an error occurs.78 SilenceUsage bool79 // The *Run functions are executed in the following order:
1 unmodified line
81 // * PreRun()82 // * Run()83 // * PostRun()84 // * PersistentPostRun()83 // All functions get the same args, the arguments after the command name84 // PersistentPreRun: children of this command will inherit and execute85 // All functions get the same args, the arguments after the command name.86 // PersistentPreRun: children of this command will inherit and execute.87 PersistentPreRun func(cmd *Command, args []string)86 // PersistentPreRunE: PersistentPreRun but returns an error88 // PersistentPreRunE: PersistentPreRun but returns an error.89 PersistentPreRunE func(cmd *Command, args []string) error90 // PreRun: children of this command will not inherit.91 PreRun func(cmd *Command, args []string)90 // PreRunE: PreRun but returns an error92 // PreRunE: PreRun but returns an error.93 PreRunE func(cmd *Command, args []string) error92 // Run: Typically the actual work function. Most commands will only implement this94 // Run: Typically the actual work function. Most commands will only implement this.95 Run func(cmd *Command, args []string)94 // RunE: Run but returns an error96 // RunE: Run but returns an error.97 RunE func(cmd *Command, args []string) error98 // PostRun: run after the Run command.99 PostRun func(cmd *Command, args []string)98 // PostRunE: PostRun but returns an error100 // PostRunE: PostRun but returns an error.101 PostRunE func(cmd *Command, args []string) error100 // PersistentPostRun: children of this command will inherit and execute after PostRun102 // PersistentPostRun: children of this command will inherit and execute after PostRun.103 PersistentPostRun func(cmd *Command, args []string)102 // PersistentPostRunE: PersistentPostRun but returns an error104 // PersistentPostRunE: PersistentPostRun but returns an error.105 PersistentPostRunE func(cmd *Command, args []string) error104 // DisableAutoGenTag remove106 // DisableFlagParsing disables the flag parsing.107 // If this is true all flags will be passed to the command as arguments.108 DisableFlagParsing bool109 // DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...")110 // will be printed by generating docs for this command.111 DisableAutoGenTag bool112113 // DisableSuggestions disables the suggestions based on Levenshtein distance114 // that go along with 'unknown command' messages.115 DisableSuggestions bool116 // SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions.117 // Must be > 0.118 SuggestionsMinimumDistance int119106 // Commands is the list of commands supported by this program.120 // commands is the list of commands supported by this program.121 commands []*Command108 // Parent Command for this command122 // parent is a parent command for this command.123 parent *Command110 // max lengths of commands' string lengths for use in padding124 // max lengths of commands' string lengths for use in padding.125 commandsMaxUseLen int126 commandsMaxCommandPathLen int127 commandsMaxNameLen int114 // is commands slice are sorted or not128 // commandsAreSorted defines, if commands slice are sorted or not.129 commandsAreSorted bool116130 // flagErrorBuf contains all error messages from pflag.131 flagErrorBuf *bytes.Buffer119120 args []string // actual args parsed from flags121 output io.Writer // out writer if set in SetOutput(w)122 usageFunc func(*Command) error // Usage can be defined by application123 usageTemplate string // Can be defined by Application132 // args is actual args parsed from flags.133 args []string134 // output is an output writer defined by user.135 output io.Writer136 // usageFunc is usage func defined by user.137 usageFunc func(*Command) error138 // usageTemplate is usage template defined by user.139 usageTemplate string140 // flagErrorFunc is func defined by user and it's called when the parsing of141 // flags returns an error.142 flagErrorFunc func(*Command, error) error125 helpTemplate string // Can be defined by Application126 helpFunc func(*Command, []string) // Help can be defined by application127 helpCommand *Command // The help command128 // The global normalization function that we can use on every pFlag set and children commands143 // helpTemplate is help template defined by user.144 helpTemplate string145 // helpFunc is help func defined by user.146 helpFunc func(*Command, []string)147 // helpCommand is command with usage 'help'. If it not defined by user,148 // cobra uses default help command.149 helpCommand *Command150 // globNormFunc is the global normalization function151 // that we can use on every pflag set and children commands152 globNormFunc func(f *flag.FlagSet, name string) flag.NormalizedName130131 // Disable the suggestions based on Levenshtein distance that go along with 'unknown command' messages132 DisableSuggestions bool133 // If displaying suggestions, allows to set the minimum levenshtein distance to display, must be > 0134 SuggestionsMinimumDistance int135136 // Disable the flag parsing. If this is true all flags will be passed to the command as arguments.137 DisableFlagParsing bool153}154155// SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden156// particularly useful when testing.
1123 unmodified lines