diff --git a/flag_bool.go b/flag_bool.go index b21d516..3e19bde 100644 --- a/flag_bool.go +++ b/flag_bool.go @@ -51,8 +51,13 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) error { } f.Value = valBool - f.HasBeenSet = true + } else { + // empty value implies that the env is defined but set to empty string, we have to assume that this is + // what the user wants. If user doesnt want this then the env needs to be deleted or the flag removed from + // file + f.Value = false } + f.HasBeenSet = true } for _, name := range f.Names() { diff --git a/flag_generic.go b/flag_generic.go index 680eeb9..6a19aef 100644 --- a/flag_generic.go +++ b/flag_generic.go @@ -50,7 +50,7 @@ func (f *GenericFlag) GetEnvVars() []string { // Apply takes the flagset and calls Set on the generic flag with the value // provided by the user for parsing by the flag -func (f GenericFlag) Apply(set *flag.FlagSet) error { +func (f *GenericFlag) Apply(set *flag.FlagSet) error { if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { if err := f.Value.Set(val); err != nil { diff --git a/flag_test.go b/flag_test.go index 456d1b8..001bc22 100644 --- a/flag_test.go +++ b/flag_test.go @@ -169,6 +169,10 @@ func TestFlagsFromEnv(t *testing.T) { if !reflect.DeepEqual(ctx.Value(test.flag.Names()[0]), test.output) { t.Errorf("ex:%01d expected %q to be parsed as %#v, instead was %#v", i, test.input, test.output, ctx.Value(test.flag.Names()[0])) } + if !f.IsSet() { + t.Errorf("Flag %s not set", f.Names()[0]) + } + return nil }, } diff --git a/godoc-current.txt b/godoc-current.txt index a6a3887..f3be3c0 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -5,24 +5,24 @@ line Go applications. cli is designed to be easy to understand and write, the most simple cli application can be written as follows: func main() { - (&cli.App{}).Run(os.Args) + (&cli.App{}).Run(os.Args) } Of course this application does not do much, so let's make this an actual application: - func main() { - app := &cli.App{ - Name: "greet", - Usage: "say a greeting", - Action: func(c *cli.Context) error { - fmt.Println("Greetings") - return nil - }, - } - - app.Run(os.Args) - } + func main() { + app := &cli.App{ + Name: "greet", + Usage: "say a greeting", + Action: func(c *cli.Context) error { + fmt.Println("Greetings") + return nil + }, + } + + app.Run(os.Args) + } VARIABLES @@ -1073,7 +1073,7 @@ type GenericFlag struct { } GenericFlag is a flag with type Generic -func (f GenericFlag) Apply(set *flag.FlagSet) error +func (f *GenericFlag) Apply(set *flag.FlagSet) error Apply takes the flagset and calls Set on the generic flag with the value provided by the user for parsing by the flag