mirror of https://github.com/spf13/cobra.git
Fix docs for Command
This commit is contained in:
parent
6bfe2ba1a2
commit
4db577d34d
121
command.go
121
command.go
|
@ -28,49 +28,51 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command is just that, a command for your application.
|
// Command is just that, a command for your application.
|
||||||
// eg. 'go run' ... 'run' is the command. Cobra requires
|
// E.g. 'go run ...' - 'run' is the command. Cobra requires
|
||||||
// you to define the usage and description as part of your command
|
// you to define the usage and description as part of your command
|
||||||
// definition to ensure usability.
|
// definition to ensure usability.
|
||||||
type Command struct {
|
type Command struct {
|
||||||
// Name is the command name, usually the executable's name.
|
// name is the command name, usually the executable's name.
|
||||||
name string
|
name string
|
||||||
// The one-line usage message.
|
// Use is the one-line usage message.
|
||||||
Use string
|
Use string
|
||||||
// An array of aliases that can be used instead of the first word in Use.
|
// Aliases is an array of aliases that can be used instead of the first word in Use.
|
||||||
Aliases []string
|
Aliases []string
|
||||||
// An array of command names for which this command will be suggested - similar to aliases but only suggests.
|
// SuggestFor is an array of command names for which this command will be suggested -
|
||||||
|
// similar to aliases but only suggests.
|
||||||
SuggestFor []string
|
SuggestFor []string
|
||||||
// The short description shown in the 'help' output.
|
// Short is the short description shown in the 'help' output.
|
||||||
Short string
|
Short string
|
||||||
// The long message shown in the 'help <this-command>' output.
|
// Long is the long message shown in the 'help <this-command>' output.
|
||||||
Long string
|
Long string
|
||||||
// Examples of how to use the command
|
// Example is examples of how to use the command.
|
||||||
Example string
|
Example string
|
||||||
// List of all valid non-flag arguments that are accepted in bash completions
|
// ValidArgs is list of all valid non-flag arguments that are accepted in bash completions
|
||||||
ValidArgs []string
|
ValidArgs []string
|
||||||
// List of aliases for ValidArgs. These are not suggested to the user in the bash
|
// ArgAliases is List of aliases for ValidArgs.
|
||||||
// completion, but accepted if entered manually.
|
// These are not suggested to the user in the bash completion,
|
||||||
|
// but accepted if entered manually.
|
||||||
ArgAliases []string
|
ArgAliases []string
|
||||||
// Custom functions used by the bash autocompletion generator
|
// BashCompletionFunction is custom functions used by the bash autocompletion generator.
|
||||||
BashCompletionFunction string
|
BashCompletionFunction string
|
||||||
// Is this command deprecated and should print this string when used?
|
// Deprecated defines, if this command deprecated and should print this string when used.
|
||||||
Deprecated string
|
Deprecated string
|
||||||
// Is this command hidden and should NOT show up in the list of available commands?
|
// Hidden defines, if this command hidden and should NOT show up in the list of available commands.
|
||||||
Hidden bool
|
Hidden bool
|
||||||
// Annotations are key/value pairs that can be used by applications to identify or
|
// Annotations are key/value pairs that can be used by applications to identify or
|
||||||
// group commands
|
// group commands.
|
||||||
Annotations map[string]string
|
Annotations map[string]string
|
||||||
// Full set of flags
|
// flags is full set of flags.
|
||||||
flags *flag.FlagSet
|
flags *flag.FlagSet
|
||||||
// Set of flags childrens of this command will inherit
|
// pflags contains persistent flags.
|
||||||
pflags *flag.FlagSet
|
pflags *flag.FlagSet
|
||||||
// Flags that are declared specifically by this command (not inherited).
|
// lflags contains local flags.
|
||||||
lflags *flag.FlagSet
|
lflags *flag.FlagSet
|
||||||
// Inherited flags.
|
// iflags contains inherited flags.
|
||||||
iflags *flag.FlagSet
|
iflags *flag.FlagSet
|
||||||
// All persistent flags of cmd's parents.
|
// parentsPflags is all persistent flags of cmd's parents.
|
||||||
parentsPflags *flag.FlagSet
|
parentsPflags *flag.FlagSet
|
||||||
// SilenceErrors is an option to quiet errors down stream
|
// SilenceErrors is an option to quiet errors down stream.
|
||||||
SilenceErrors bool
|
SilenceErrors bool
|
||||||
// Silence Usage is an option to silence usage when an error occurs.
|
// Silence Usage is an option to silence usage when an error occurs.
|
||||||
SilenceUsage bool
|
SilenceUsage bool
|
||||||
|
@ -80,61 +82,74 @@ type Command struct {
|
||||||
// * Run()
|
// * Run()
|
||||||
// * PostRun()
|
// * PostRun()
|
||||||
// * PersistentPostRun()
|
// * PersistentPostRun()
|
||||||
// All functions get the same args, the arguments after the command name
|
// All functions get the same args, the arguments after the command name.
|
||||||
// PersistentPreRun: children of this command will inherit and execute
|
// PersistentPreRun: children of this command will inherit and execute.
|
||||||
PersistentPreRun func(cmd *Command, args []string)
|
PersistentPreRun func(cmd *Command, args []string)
|
||||||
// PersistentPreRunE: PersistentPreRun but returns an error
|
// PersistentPreRunE: PersistentPreRun but returns an error.
|
||||||
PersistentPreRunE func(cmd *Command, args []string) error
|
PersistentPreRunE func(cmd *Command, args []string) error
|
||||||
// PreRun: children of this command will not inherit.
|
// PreRun: children of this command will not inherit.
|
||||||
PreRun func(cmd *Command, args []string)
|
PreRun func(cmd *Command, args []string)
|
||||||
// PreRunE: PreRun but returns an error
|
// PreRunE: PreRun but returns an error.
|
||||||
PreRunE func(cmd *Command, args []string) error
|
PreRunE func(cmd *Command, args []string) error
|
||||||
// Run: Typically the actual work function. Most commands will only implement this
|
// Run: Typically the actual work function. Most commands will only implement this.
|
||||||
Run func(cmd *Command, args []string)
|
Run func(cmd *Command, args []string)
|
||||||
// RunE: Run but returns an error
|
// RunE: Run but returns an error.
|
||||||
RunE func(cmd *Command, args []string) error
|
RunE func(cmd *Command, args []string) error
|
||||||
// PostRun: run after the Run command.
|
// PostRun: run after the Run command.
|
||||||
PostRun func(cmd *Command, args []string)
|
PostRun func(cmd *Command, args []string)
|
||||||
// PostRunE: PostRun but returns an error
|
// PostRunE: PostRun but returns an error.
|
||||||
PostRunE func(cmd *Command, args []string) error
|
PostRunE func(cmd *Command, args []string) error
|
||||||
// PersistentPostRun: children of this command will inherit and execute after PostRun
|
// PersistentPostRun: children of this command will inherit and execute after PostRun.
|
||||||
PersistentPostRun func(cmd *Command, args []string)
|
PersistentPostRun func(cmd *Command, args []string)
|
||||||
// PersistentPostRunE: PersistentPostRun but returns an error
|
// PersistentPostRunE: PersistentPostRun but returns an error.
|
||||||
PersistentPostRunE func(cmd *Command, args []string) error
|
PersistentPostRunE func(cmd *Command, args []string) error
|
||||||
// DisableAutoGenTag remove
|
// DisableFlagParsing disables the flag parsing.
|
||||||
|
// If this is true all flags will be passed to the command as arguments.
|
||||||
|
DisableFlagParsing bool
|
||||||
|
// DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...")
|
||||||
|
// will be printed by generating docs for this command.
|
||||||
DisableAutoGenTag bool
|
DisableAutoGenTag bool
|
||||||
// Commands is the list of commands supported by this program.
|
|
||||||
|
// DisableSuggestions disables the suggestions based on Levenshtein distance
|
||||||
|
// that go along with 'unknown command' messages.
|
||||||
|
DisableSuggestions bool
|
||||||
|
// SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions.
|
||||||
|
// Must be > 0.
|
||||||
|
SuggestionsMinimumDistance int
|
||||||
|
|
||||||
|
// commands is the list of commands supported by this program.
|
||||||
commands []*Command
|
commands []*Command
|
||||||
// Parent Command for this command
|
// parent is a parent command for this command.
|
||||||
parent *Command
|
parent *Command
|
||||||
// max lengths of commands' string lengths for use in padding
|
// max lengths of commands' string lengths for use in padding.
|
||||||
commandsMaxUseLen int
|
commandsMaxUseLen int
|
||||||
commandsMaxCommandPathLen int
|
commandsMaxCommandPathLen int
|
||||||
commandsMaxNameLen int
|
commandsMaxNameLen int
|
||||||
// is commands slice are sorted or not
|
// commandsAreSorted defines, if commands slice are sorted or not.
|
||||||
commandsAreSorted bool
|
commandsAreSorted bool
|
||||||
|
|
||||||
// flagErrorBuf contains all error messages from pflag.
|
// flagErrorBuf contains all error messages from pflag.
|
||||||
flagErrorBuf *bytes.Buffer
|
flagErrorBuf *bytes.Buffer
|
||||||
|
// args is actual args parsed from flags.
|
||||||
args []string // actual args parsed from flags
|
args []string
|
||||||
output io.Writer // out writer if set in SetOutput(w)
|
// output is an output writer defined by user.
|
||||||
usageFunc func(*Command) error // Usage can be defined by application
|
output io.Writer
|
||||||
usageTemplate string // Can be defined by Application
|
// usageFunc is usage func defined by user.
|
||||||
|
usageFunc func(*Command) error
|
||||||
|
// usageTemplate is usage template defined by user.
|
||||||
|
usageTemplate string
|
||||||
|
// flagErrorFunc is func defined by user and it's called when the parsing of
|
||||||
|
// flags returns an error.
|
||||||
flagErrorFunc func(*Command, error) error
|
flagErrorFunc func(*Command, error) error
|
||||||
helpTemplate string // Can be defined by Application
|
// helpTemplate is help template defined by user.
|
||||||
helpFunc func(*Command, []string) // Help can be defined by application
|
helpTemplate string
|
||||||
helpCommand *Command // The help command
|
// helpFunc is help func defined by user.
|
||||||
// The global normalization function that we can use on every pFlag set and children commands
|
helpFunc func(*Command, []string)
|
||||||
|
// helpCommand is command with usage 'help'. If it not defined by user,
|
||||||
|
// cobra uses default help command.
|
||||||
|
helpCommand *Command
|
||||||
|
// globNormFunc is the global normalization function
|
||||||
|
// that we can use on every pflag set and children commands
|
||||||
globNormFunc func(f *flag.FlagSet, name string) flag.NormalizedName
|
globNormFunc func(f *flag.FlagSet, name string) flag.NormalizedName
|
||||||
|
|
||||||
// Disable the suggestions based on Levenshtein distance that go along with 'unknown command' messages
|
|
||||||
DisableSuggestions bool
|
|
||||||
// If displaying suggestions, allows to set the minimum levenshtein distance to display, must be > 0
|
|
||||||
SuggestionsMinimumDistance int
|
|
||||||
|
|
||||||
// Disable the flag parsing. If this is true all flags will be passed to the command as arguments.
|
|
||||||
DisableFlagParsing bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden
|
// SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden
|
||||||
|
|
Loading…
Reference in New Issue