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