adding string alias and test
This commit is contained in:
parent
e0db267492
commit
50bbb4a53e
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"}),
|
||||
|
Loading…
Reference in New Issue
Block a user