diff --git a/altsrc/flag.go b/altsrc/flag.go index daac809..1783e1b 100644 --- a/altsrc/flag.go +++ b/altsrc/flag.go @@ -142,13 +142,15 @@ func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte // ApplyInputSourceValue applies a String value to the flagSet if required func (f *StringFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error { if f.set != nil && !(cCtx.IsSet(f.Name) || isEnvVarSet(f.EnvVars)) && isc.isSet(f.StringFlag.Name) { - value, err := isc.String(f.StringFlag.Name) - if err != nil { - return err - } - if value != "" { - for _, name := range f.Names() { - _ = f.set.Set(name, value) + for _, name := range f.StringFlag.Names(){ + if isc.isSet(name) { + value, err := isc.String(name) + if err != nil { + return err + } + for _, n := range f.Names() { + _ = f.set.Set(n, value) + } } } } diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index d97c184..47a280a 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -220,6 +220,20 @@ func TestBoolApplyInputSourceMethodEnvVarSet(t *testing.T) { refute(t, true, c.Bool("test")) } +func TestStringApplyInputSourceMethodSet_Alias(t *testing.T) { + tis := testApplyInputSource{ + Flag: NewStringFlag(&cli.StringFlag{Name: "test", Aliases: []string{"test_alias"}}), + FlagName: "test_alias", + MapValue: "hello", + ContextValueString: "goodbye", + } + c := runTest(t, tis) + expect(t, "goodbye", c.String("test_alias")) + + c = runRacyTest(t, tis) + refute(t, "goodbye", c.String("test_alias")) +} + func TestStringApplyInputSourceMethodSet(t *testing.T) { tis := testApplyInputSource{ Flag: NewStringFlag(&cli.StringFlag{Name: "test"}),