mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Adjustments to documentation (#1656)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This commit is contained in:
parent
fe08012edd
commit
7e289f46f1
2 changed files with 17 additions and 14 deletions
|
@ -40,9 +40,9 @@ The best applications read like sentences when used, and as a result, users
|
||||||
intuitively know how to interact with them.
|
intuitively know how to interact with them.
|
||||||
|
|
||||||
The pattern to follow is
|
The pattern to follow is
|
||||||
`APPNAME VERB NOUN --ADJECTIVE.`
|
`APPNAME VERB NOUN --ADJECTIVE`
|
||||||
or
|
or
|
||||||
`APPNAME COMMAND ARG --FLAG`
|
`APPNAME COMMAND ARG --FLAG`.
|
||||||
|
|
||||||
A few good real world examples may better illustrate this point.
|
A few good real world examples may better illustrate this point.
|
||||||
|
|
||||||
|
|
|
@ -462,28 +462,29 @@ create' is called. Every command will automatically have the '--help' flag adde
|
||||||
The following output is automatically generated by Cobra. Nothing beyond the
|
The following output is automatically generated by Cobra. Nothing beyond the
|
||||||
command and flag definitions are needed.
|
command and flag definitions are needed.
|
||||||
|
|
||||||
$ cobra help
|
$ cobra-cli help
|
||||||
|
|
||||||
Cobra is a CLI library for Go that empowers applications.
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
This application is a tool to generate the needed files
|
This application is a tool to generate the needed files
|
||||||
to quickly create a Cobra application.
|
to quickly create a Cobra application.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
cobra [command]
|
cobra-cli [command]
|
||||||
|
|
||||||
Available Commands:
|
Available Commands:
|
||||||
add Add a command to a Cobra Application
|
add Add a command to a Cobra Application
|
||||||
|
completion Generate the autocompletion script for the specified shell
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialize a Cobra Application
|
init Initialize a Cobra Application
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
||||||
--config string config file (default is $HOME/.cobra.yaml)
|
--config string config file (default is $HOME/.cobra.yaml)
|
||||||
-h, --help help for cobra
|
-h, --help help for cobra-cli
|
||||||
-l, --license string name of license for the project
|
-l, --license string name of license for the project
|
||||||
--viper use Viper for configuration (default true)
|
--viper use Viper for configuration
|
||||||
|
|
||||||
Use "cobra [command] --help" for more information about a command.
|
Use "cobra-cli [command] --help" for more information about a command.
|
||||||
|
|
||||||
|
|
||||||
Help is just a command like any other. There is no special logic or behavior
|
Help is just a command like any other. There is no special logic or behavior
|
||||||
|
@ -492,7 +493,7 @@ around it. In fact, you can provide your own if you want.
|
||||||
### Defining your own help
|
### Defining your own help
|
||||||
|
|
||||||
You can provide your own Help command or your own template for the default command to use
|
You can provide your own Help command or your own template for the default command to use
|
||||||
with following functions:
|
with the following functions:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
cmd.SetHelpCommand(cmd *Command)
|
cmd.SetHelpCommand(cmd *Command)
|
||||||
|
@ -511,22 +512,23 @@ showing the user the 'usage'.
|
||||||
You may recognize this from the help above. That's because the default help
|
You may recognize this from the help above. That's because the default help
|
||||||
embeds the usage as part of its output.
|
embeds the usage as part of its output.
|
||||||
|
|
||||||
$ cobra --invalid
|
$ cobra-cli --invalid
|
||||||
Error: unknown flag: --invalid
|
Error: unknown flag: --invalid
|
||||||
Usage:
|
Usage:
|
||||||
cobra [command]
|
cobra-cli [command]
|
||||||
|
|
||||||
Available Commands:
|
Available Commands:
|
||||||
add Add a command to a Cobra Application
|
add Add a command to a Cobra Application
|
||||||
|
completion Generate the autocompletion script for the specified shell
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialize a Cobra Application
|
init Initialize a Cobra Application
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
||||||
--config string config file (default is $HOME/.cobra.yaml)
|
--config string config file (default is $HOME/.cobra.yaml)
|
||||||
-h, --help help for cobra
|
-h, --help help for cobra-cli
|
||||||
-l, --license string name of license for the project
|
-l, --license string name of license for the project
|
||||||
--viper use Viper for configuration (default true)
|
--viper use Viper for configuration
|
||||||
|
|
||||||
Use "cobra [command] --help" for more information about a command.
|
Use "cobra [command] --help" for more information about a command.
|
||||||
|
|
||||||
|
@ -645,7 +647,7 @@ Did you mean this?
|
||||||
Run 'hugo --help' for usage.
|
Run 'hugo --help' for usage.
|
||||||
```
|
```
|
||||||
|
|
||||||
Suggestions are automatic based on every subcommand registered and use an implementation of [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion.
|
Suggestions are automatically generated based on existing subcommands and use an implementation of [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion.
|
||||||
|
|
||||||
If you need to disable suggestions or tweak the string distance in your command, use:
|
If you need to disable suggestions or tweak the string distance in your command, use:
|
||||||
|
|
||||||
|
@ -659,7 +661,8 @@ or
|
||||||
command.SuggestionsMinimumDistance = 1
|
command.SuggestionsMinimumDistance = 1
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also explicitly set names for which a given command will be suggested using the `SuggestFor` attribute. This allows suggestions for strings that are not close in terms of string distance, but makes sense in your set of commands and for some which you don't want aliases. Example:
|
You can also explicitly set names for which a given command will be suggested using the `SuggestFor` attribute. This allows suggestions for strings that are not close in terms of string distance, but make sense in your set of commands but for which
|
||||||
|
you don't want aliases. Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ kubectl remove
|
$ kubectl remove
|
||||||
|
|
Loading…
Reference in a new issue