adding int alias and test
This commit is contained in:
parent
50bbb4a53e
commit
5a5789af7a
@ -186,12 +186,16 @@ func (f *PathFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
|
||||
// ApplyInputSourceValue applies a int value to the flagSet if required
|
||||
func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error {
|
||||
if f.set != nil && !(cCtx.IsSet(f.Name) || isEnvVarSet(f.EnvVars)) && isc.isSet(f.IntFlag.Name) {
|
||||
value, err := isc.Int(f.IntFlag.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, name := range f.Names() {
|
||||
_ = f.set.Set(name, strconv.FormatInt(int64(value), 10))
|
||||
for _, name := range f.IntFlag.Names() {
|
||||
if isc.isSet(name) {
|
||||
value, err := isc.Int(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range f.Names() {
|
||||
_ = f.set.Set(n, strconv.FormatInt(int64(value), 10))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -332,6 +332,19 @@ func TestPathApplyInputSourceMethodEnvVarSet(t *testing.T) {
|
||||
refute(t, "goodbye", c.String("test"))
|
||||
}
|
||||
|
||||
func TestIntApplyInputSourceMethodSet_Alias(t *testing.T) {
|
||||
tis := testApplyInputSource{
|
||||
Flag: NewIntFlag(&cli.IntFlag{Name: "test", Aliases: []string{"test_alias"}}),
|
||||
FlagName: "test",
|
||||
MapValue: 15,
|
||||
}
|
||||
c := runTest(t, tis)
|
||||
expect(t, 15, c.Int("test_alias"))
|
||||
|
||||
c = runRacyTest(t, tis)
|
||||
refute(t, 15, c.Int("test_alias"))
|
||||
}
|
||||
|
||||
func TestIntApplyInputSourceMethodSet(t *testing.T) {
|
||||
tis := testApplyInputSource{
|
||||
Flag: NewIntFlag(&cli.IntFlag{Name: "test"}),
|
||||
|
Loading…
Reference in New Issue
Block a user