Currently cli silently (aside from IntSlice and Int64Slice which oddly
printed directly to the error stream) ignores failures that occur when
parsing environment variables for their value for flags that define
environment variables. Instead, we should propogate up the error to the
user.
This is accomplished in a backwards compatible manner by adding a new,
internal, interface which defines an applyWithError function that all
flags here define. In v2, when we can modify the interface, we can drop
this secondary interface and modify `Apply` to return an error.
When assigning values to flags (also when interogatting via
`context.(Global)IsSet`.
For boolean flags, consider empty as `false`.
Using `syscall.Getenv` rather than `os.LookupEnv` in order to support
older Golang versions.
by defining `cli.DefaultFlagStringFunc` with a default value that uses
`withEnvHint`, conditionally running a given flag's `FormatValueHelp` if
present.
Closes#257
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.
Feels like it may have been copied from StringSliceFlag or something,
but update the output to be more consistent with other single value
flags.
Also added comments to the String and Apply functions.
This fixes StringSliceFlag default usage text to be consistent with
IntegerSliceFlag.
Before:
-f [] `-f option -f option` port forwarding rules
After:
-f '-f option -f option' port forwarding rules
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Compared to BoolFlag type, BoolTFlag treats 'true' as the default value
for the flag.
Without it, we have to use --no-action flag if we set the action is done
in default. But sometimes it is bad to maintain flags with negative meanings.
And it will be painful if we change the default value for the flag.
As this implementation, it keeps all existing functionality. So it
is compatible with old versions.