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
|
// ApplyInputSourceValue applies a int value to the flagSet if required
|
||||||
func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error {
|
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) {
|
if f.set != nil && !(cCtx.IsSet(f.Name) || isEnvVarSet(f.EnvVars)) && isc.isSet(f.IntFlag.Name) {
|
||||||
value, err := isc.Int(f.IntFlag.Name)
|
for _, name := range f.IntFlag.Names() {
|
||||||
if err != nil {
|
if isc.isSet(name) {
|
||||||
return err
|
value, err := isc.Int(name)
|
||||||
}
|
if err != nil {
|
||||||
for _, name := range f.Names() {
|
return err
|
||||||
_ = f.set.Set(name, strconv.FormatInt(int64(value), 10))
|
}
|
||||||
|
for _, n := range f.Names() {
|
||||||
|
_ = f.set.Set(n, strconv.FormatInt(int64(value), 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -332,6 +332,19 @@ func TestPathApplyInputSourceMethodEnvVarSet(t *testing.T) {
|
|||||||
refute(t, "goodbye", c.String("test"))
|
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) {
|
func TestIntApplyInputSourceMethodSet(t *testing.T) {
|
||||||
tis := testApplyInputSource{
|
tis := testApplyInputSource{
|
||||||
Flag: NewIntFlag(&cli.IntFlag{Name: "test"}),
|
Flag: NewIntFlag(&cli.IntFlag{Name: "test"}),
|
||||||
|
Loading…
Reference in New Issue
Block a user