The default help template relies on the String() method of Flag
to render the flag. For most flag types, String() indirects through
FlagStringer, so that is the best place to customize flag rendering.
FlagStringer was not called for slice flags because their help output
differs from other flags in two ways: there can be multiple default
values, and the flag name is shown two times to indicate that the flag
can be specified multiple times.
To make multiple values work in the FlagStringer, I simply changed
GetValue() to return all values.
Showing the flag more than once is achieved through a new interface,
DocGenerationSliceFlag, which the FlagStringer uses to decide whether
the flag is a slice flag type.
The default help template relies on the String() method of Flag
to render the flag. For most flag types, String() indirects through
FlagStringer, so that is the best place to customize flag rendering.
FlagStringer was not called for slice flags because their help output
differs from other flags in two ways: there can be multiple default
values, and the flag name is shown two times to indicate that the flag
can be specified multiple times.
To make multiple values work in the FlagStringer, I simply changed
GetValue() to return all values.
Showing the flag more than once is achieved through a new interface,
DocGenerationSliceFlag, which the FlagStringer uses to decide whether
the flag is a slice flag type.
strings.Split(s, sep) returns a slice of a single element containing s
if sep is not found in s. This is true even if s is empty.
As a result, every call to flagFromEnvOrFile results in an attempt to
open a file with empty name. This is seen from strace as
[pid 3287620] openat(AT_FDCWD, "", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 3287620] openat(AT_FDCWD, "", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
...
To fix, check if the string is empty before calling ReadFile.
This also fixes cases where filePath is non-empty but has extra commas.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
move bool to the end of the return arguments
remove "from " prefix in the source/fromWhere description
remove TODO notes from functions that don't currently perform error checking
If you allow a flag to be set from environment variables or files and
a parse error occurs from one of them, it is very useful for the error
message to mention where the value came from.
Without this, it can be difficult to notice an error caused by an
unexpected environment variable being set.
Implements #1167.
While `HideHelp` hides both `help` command and `--help` flag, `HideHelpCommand`
only hides `help` command and leave `--help` flag as-is.
The behavior of `HideHelp` is untouched in this commit.
Fix#523
Replace #636
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
The usage of the `(default: …)` strings are a bit error prone so we now
refactor them into a dedicated helper function.
Signed-off-by: Sascha Grunert <sgrunert@suse.com>