Report the source of a value when we cannot parse it

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.
This commit is contained in:
Mostyn Bramley-Moore
2020-07-30 12:05:11 +02:00
parent ec731febcc
commit 500d6b04e6
17 changed files with 50 additions and 48 deletions

View File

@@ -57,7 +57,8 @@ func (f *StringFlag) GetValue() string {
// Apply populates the flag given the flag set and environment
func (f *StringFlag) Apply(set *flag.FlagSet) error {
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
// TODO: how to report source?
if val, ok, _ := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
f.Value = val
f.HasBeenSet = true
}