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.
When checking if environment variables are set.
We don't support pointer flags currently (though this is the default in
the `v2` branch), but this fixes#516
This appeared to be the least messy approach to hack in support for
IsSet also checking environment variables to see if a particular
cli.Flag was set without making backwards incompatible changes to the
interface.
I intend to fix this more properly in v2, probably by adding another
method to the cli.Flag interface to push the responsibility down as it
occurred to me that it was really the `Flag`s themselves that offer
support for configuration via the environment as opposed to the
`context` or other supporting structures. This opens the door for the
anything implementing the `Flag` interface to have additional sources of
input while still supporting `context.IsSet`.
This fixes a regression introduced by #227. When looking up global flags by walking up the parent context's we need to consider the special case when we are starting at the very top and there is no parent context to start the traversal.
Fixes#252
This change allows a context value to be set after parsing. The use case is updating default settings in a Before func.
An example usage:
```
f, err := os.Open(configPath)
if err == nil {
config, err := docli.NewConfig(f)
if err != nil {
panic(err)
}
c.Set("token", config.APIKey)
}
```
The usecase:
my-cli user <USERID> set <FIELD> <VALUE>
Being able to swap <USERID> with set argument, we can have nested subcommands while preserving all variable arguments along the way.
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.