add support for duration flag
This commit is contained in:
parent
5a5789af7a
commit
c512a283ea
@ -204,12 +204,16 @@ func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContex
|
||||
// ApplyInputSourceValue applies a Duration value to the flagSet if required
|
||||
func (f *DurationFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error {
|
||||
if f.set != nil && !(cCtx.IsSet(f.Name) || isEnvVarSet(f.EnvVars)) && isc.isSet(f.DurationFlag.Name) {
|
||||
value, err := isc.Duration(f.DurationFlag.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, name := range f.Names() {
|
||||
_ = f.set.Set(name, value.String())
|
||||
for _, name := range f.DurationFlag.Names() {
|
||||
if isc.isSet(name) {
|
||||
value, err := isc.Duration(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range f.Names() {
|
||||
_ = f.set.Set(n, value.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -400,6 +400,19 @@ func TestIntApplyInputSourceMethodEnvVarSet(t *testing.T) {
|
||||
refute(t, 12, c.Int("test"))
|
||||
}
|
||||
|
||||
func TestDurationApplyInputSourceMethodSet_Alias(t *testing.T) {
|
||||
tis := testApplyInputSource{
|
||||
Flag: NewDurationFlag(&cli.DurationFlag{Name: "test", Aliases: []string{"test_alias"}}),
|
||||
FlagName: "test",
|
||||
MapValue: 30 * time.Second,
|
||||
}
|
||||
c := runTest(t, tis)
|
||||
expect(t, 30*time.Second, c.Duration("test_alias"))
|
||||
|
||||
c = runRacyTest(t, tis)
|
||||
refute(t, 30*time.Second, c.Duration("test_alias"))
|
||||
}
|
||||
|
||||
func TestDurationApplyInputSourceMethodSet(t *testing.T) {
|
||||
tis := testApplyInputSource{
|
||||
Flag: NewDurationFlag(&cli.DurationFlag{Name: "test"}),
|
||||
|
Loading…
Reference in New Issue
Block a user