Users can now use custom flags types (conforming to the Flag interface)
in their applications. They can also use custom flags for the three
global flags (Help, Version, bash completion).
Most of the changes here remove trailing whitespace, but I also add
code to select "AUTHOR" or "AUTHORS" as appropriate instead of the
previous "AUTHOR(S)". The template for listing with an entry per line
is:
{{range $index, $entry := pipeline}}{{if $index}}
{{end}}{{$entry}}{{end}}
That range syntax is discussed in [1].
Also add a unit test, which tests both these whitespace changes and
also the earlier App.Description addition.
[1]: https://golang.org/pkg/text/template/#hdr-Variables
The refactoring is required since completion is also supported for zsh
shell.
Refactoring details:
- flag generate-bash-completion -> generate-completion
- var EnableBashCompletion -> EnableShellCompletion
- var BashComplete -> ShellComplete
- var BashCompletionFlag -> GenerateCompletionFlag
- type BashCompleteFunc -> ShellCompleteFunc
Currently, if an action is specified on a subcommand, it ignores the
`-h` and `--help` flags if passed to the subcommand, e.g.:
`foo bar -h`
would call the default action on `bar` rather than show the help
documentation.
Fixes#477
Using tabs for alignment is troubling if the output is used for anything besides display in a terminal (or if the user's terminal allows for adjustment of the default tab size), as noted by the documentation for `tabwriter` (https://golang.org/pkg/text/tabwriter/#Writer.Init):
> (for correct-looking results, tabwidth must correspond to the tab width in the viewer displaying the result)
The safer solution is to use `' '` as the `padchar`, which only carries the assumption of a fixed-width font (which is a more reasonable assumption than a fixed, constant tab size).
Currently it just prints the help message and exits 0.
We do this by modifying the helpCommand and helpSubcommand cli.Commands
to return an error if they are called with an unknown subcommand. This
propogates up to the app which exits with 3 and prints the error.
Thanks to @danslimmon for the initial approach!
Fixes#276
plus breaking out "setup" portion of `App.Run` into its own method, cleaning up
some bits of the help templates, and allowing for runtime opt-in of displaying
template errors to stderr.
This is a way to provide hidden flags for app, command and subcommands
For example:
--generate-bash-completion global flag shouldn't be printed along
with other flags as it might generally confuse people into thinking
that 'generate' in-fact would generate a bash completion file for them
to be used along with their app.
Also in general one would want to hide some flags for their apps.
Just place all subcommands in categories, the default category will be
"" which will properly format the output (and group commands that have
no category).
Also allow subcommands to have categories.
Lastly, augment the test to check the output.
There is a panic in printHelp that can be trivially triggered when the
shell closes os.Stdout. This happens, for example, when data is piped
between a cli app and something else.
See https://github.com/helm/helm/issues/387