Update documentation
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 8bcacfe · Browse files · 2 files·+8 added−40 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+8 added−40 removed
- other:+8 added−40 removed
Provenance
- Commit
1723331- Tree
21d49ea- Author
Albert Nigmatzianov <albertnigma@gmail.com>- Committer
Albert Nigmatzianov <albertnigma@gmail.com>- Parent
8bcacfe
2 files changed+8 added−40 removed
modified:command.go+3 added-2 removed
52 unmodified lines53 54 // ValidArgs is list of all valid non-flag arguments that are accepted in bash completions55 ValidArgs []string56 57+ // Expected arguments58+ Args PositionalArgs59+60 // ArgAliases is List of aliases for ValidArgs.61 // These are not suggested to the user in the bash completion,62 // but accepted if entered manually.63 ArgAliases []string64 62- // Expected arguments63- Args PositionalArgs65 // BashCompletionFunction is custom functions used by the bash autocompletion generator.66 BashCompletionFunction string67 68 // Deprecated defines, if this command is deprecated and should print this string when used.1238 unmodified linesmodified:README.md+5 added-38 removed
115 unmodified lines116 Flag functionality is provided by the [pflag117 library](https://github.com/spf13/pflag), a fork of the flag standard library118 which maintains the same interface while adding POSIX compliance.119 120-## Usage121-122-Cobra works by creating a set of commands and then organizing them into a tree.123-The tree defines the structure of the application.124-125-Once each command is defined with its corresponding flags, then the126-tree is assigned to the commander which is finally executed.127-120 # Installing121 Using Cobra is easy. First, use `go get` to install the latest version122 of the library. This command will install the `cobra` generator executable123 along with the library and its dependencies:286 unmodified lines410 ```go411 RootCmd.AddCommand(versionCmd)412 ```413 422-### Remove a command from its parent423-424-Removing a command is not a common action in simple programs, but it allows 3rd425-parties to customize an existing command tree.426-427-In this example, we remove the existing `VersionCmd` command of an existing428-root command, and we replace it with our own version:429-430-```go431-mainlib.RootCmd.RemoveCommand(mainlib.VersionCmd)432-mainlib.RootCmd.AddCommand(versionCmd)433-```434-414 ## Working with Flags415 416 Flags provide modifiers to control how the action command operates.417 247 unmodified lines665 You can provide your own command, function or template through the following methods:666 667 ```go668 command.SetHelpCommand(cmd *Command)690-669 command.SetHelpFunc(f func(*Command, []string))692-670 command.SetHelpTemplate(s string)671 ```672 673 The latter two will also apply to any children commands.133 unmodified lines807 808 rootCmd.AddCommand(subCmd)809 810 rootCmd.SetArgs([]string{""})834- _ = rootCmd.Execute()835- fmt.Print("\n")811+ rootCmd.Execute()812+ fmt.Println()813 rootCmd.SetArgs([]string{"sub", "arg1", "arg2"})837- _ = rootCmd.Execute()814+ rootCmd.Execute()815 }816 ```817 818 28 unmodified lines847 var rootCmd = &cobra.Command{848 Use: "hugo",849 Short: "Hugo is a very fast static site generator",850 Long: `A Fast and Flexible Static Site Generator built with874- love by spf13 and friends in Go.875- Complete documentation is available at http://hugo.spf13.com`,851+love by spf13 and friends in Go.852+Complete documentation is available at http://hugo.spf13.com`,853 RunE: func(cmd *cobra.Command, args []string) error {854 // Do Stuff Here855 return errors.New("some random error")856 },56 unmodified lines913 ## Generating bash completions for your command914 915 Cobra can generate a bash-completion file. If you add more information to your command, these completions can be amazingly powerful and flexible. Read more about it in [Bash Completions](bash_completions.md).916 940-## Debugging917 942-Cobra provides a ‘DebugFlags’ method on a command which, when called, will print943-out everything Cobra knows about the flags for each command.944-945-### Example946-947-```go948-command.DebugFlags()949-```950-918 ## Extensions919 920 Libraries for extending Cobra:921 21 unmodified lines