internal/flags: fix "flag redefined" bug for alias on custom flags (#30796)

This change fixes a bug on the `DirectoryFlag` and the `BigFlag`, which would trigger a `panic` with the message "flag redefined" in case an alias was added to such a flag.
This commit is contained in:
Daniel Liu 2024-11-25 03:09:38 +08:00 committed by GitHub
parent 6485d5e3ff
commit 5e1a39d67f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -90,7 +90,7 @@ func (f *DirectoryFlag) Apply(set *flag.FlagSet) error {
} }
} }
eachName(f, func(name string) { eachName(f, func(name string) {
set.Var(&f.Value, f.Name, f.Usage) set.Var(&f.Value, name, f.Usage)
}) })
return nil return nil
} }
@ -172,7 +172,7 @@ func (f *BigFlag) Apply(set *flag.FlagSet) error {
} }
eachName(f, func(name string) { eachName(f, func(name string) {
f.Value = new(big.Int) f.Value = new(big.Int)
set.Var((*bigValue)(f.Value), f.Name, f.Usage) set.Var((*bigValue)(f.Value), name, f.Usage)
}) })
return nil return nil
} }