Divide fields of Command for readability

This commit is contained in:
Albert Nigmatzianov 2017-05-09 11:33:56 +02:00
parent 90d2fd84ad
commit eceb483eb5

View file

@ -32,40 +32,46 @@ import (
// 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 string
// Use is the one-line usage message. // Use is the one-line usage message.
Use string Use string
// Aliases is 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
// SuggestFor is an array of command names for which this command will be suggested - // SuggestFor is an array of command names for which this command will be suggested -
// similar to aliases but only suggests. // similar to aliases but only suggests.
SuggestFor []string SuggestFor []string
// Short is the short description shown in the 'help' output. // Short is the short description shown in the 'help' output.
Short string Short string
// Long is 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
// Example is examples of how to use the command. // Example is examples of how to use the command.
Example string Example string
// ValidArgs is 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
// ArgAliases is List of aliases for ValidArgs. // ArgAliases is List of aliases for ValidArgs.
// These are not suggested to the user in the bash completion, // These are not suggested to the user in the bash completion,
// but accepted if entered manually. // but accepted if entered manually.
ArgAliases []string ArgAliases []string
// BashCompletionFunction is custom functions used by the bash autocompletion generator. // BashCompletionFunction is custom functions used by the bash autocompletion generator.
BashCompletionFunction string BashCompletionFunction string
// Deprecated defines, if this command is deprecated and should print this string when used. // Deprecated defines, if this command is deprecated and should print this string when used.
Deprecated string Deprecated string
// Hidden defines, if this command is hidden and should NOT show up in the list of available commands. // Hidden defines, if this command is 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
// SilenceErrors is an option to quiet errors down stream.
SilenceErrors bool
// Silence Usage is an option to silence usage when an error occurs.
SilenceUsage bool
// The *Run functions are executed in the following order: // The *Run functions are executed in the following order:
// * PersistentPreRun() // * PersistentPreRun()
// * PreRun() // * PreRun()
@ -73,6 +79,7 @@ type Command struct {
// * 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.
@ -93,9 +100,17 @@ type Command struct {
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
// SilenceErrors is an option to quiet errors down stream.
SilenceErrors bool
// SilenceUsage is an option to silence usage when an error occurs.
SilenceUsage bool
// DisableFlagParsing disables the flag parsing. // DisableFlagParsing disables the flag parsing.
// If this is true all flags will be passed to the command as arguments. // If this is true all flags will be passed to the command as arguments.
DisableFlagParsing bool DisableFlagParsing bool
// DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...") // DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...")
// will be printed by generating docs for this command. // will be printed by generating docs for this command.
DisableAutoGenTag bool DisableAutoGenTag bool
@ -107,11 +122,13 @@ type Command struct {
// Must be > 0. // Must be > 0.
SuggestionsMinimumDistance int SuggestionsMinimumDistance int
// name is the command name, usually the executable's name.
name string
// commands is the list of commands supported by this program. // commands is the list of commands supported by this program.
commands []*Command commands []*Command
// parent is a 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