From eceb483eb5521ce55af05c94cc22b093568e5a72 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Tue, 9 May 2017 11:33:56 +0200 Subject: [PATCH] Divide fields of Command for readability --- command.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/command.go b/command.go index d6e96aef..9e6bdf30 100644 --- a/command.go +++ b/command.go @@ -32,40 +32,46 @@ import ( // you to define the usage and description as part of your command // definition to ensure usability. type Command struct { - // name is the command name, usually the executable's name. - name string // Use is the one-line usage message. Use string + // Aliases is an array of aliases that can be used instead of the first word in Use. Aliases []string + // SuggestFor is an array of command names for which this command will be suggested - // similar to aliases but only suggests. SuggestFor []string + // Short is the short description shown in the 'help' output. Short string + // Long is the long message shown in the 'help ' output. Long string + // Example is examples of how to use the command. Example string + // ValidArgs is list of all valid non-flag arguments that are accepted in bash completions ValidArgs []string + // ArgAliases is List of aliases for ValidArgs. // These are not suggested to the user in the bash completion, // but accepted if entered manually. ArgAliases []string + // BashCompletionFunction is custom functions used by the bash autocompletion generator. BashCompletionFunction string + // Deprecated defines, if this command is deprecated and should print this string when used. Deprecated string + // Hidden defines, if this command is hidden and should NOT show up in the list of available commands. Hidden bool + // Annotations are key/value pairs that can be used by applications to identify or // group commands. 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: // * PersistentPreRun() // * PreRun() @@ -73,6 +79,7 @@ type Command struct { // * PostRun() // * PersistentPostRun() // All functions get the same args, the arguments after the command name. + // // PersistentPreRun: children of this command will inherit and execute. PersistentPreRun func(cmd *Command, args []string) // PersistentPreRunE: PersistentPreRun but returns an error. @@ -93,9 +100,17 @@ type Command struct { PersistentPostRun func(cmd *Command, args []string) // PersistentPostRunE: PersistentPostRun but returns an 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. // 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 @@ -107,11 +122,13 @@ type Command struct { // Must be > 0. 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 []*Command // parent is a parent command for this 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 commandsMaxCommandPathLen int commandsMaxNameLen int