mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Use pflag.ShorthandLookup
This commit is contained in:
parent
8f0203be89
commit
4061f41c9a
1 changed files with 13 additions and 12 deletions
19
command.go
19
command.go
|
@ -369,8 +369,8 @@ func (c *Command) HelpTemplate() string {
|
|||
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
|
||||
}
|
||||
|
||||
func hasNoOptDefVal(name string, f *flag.FlagSet) bool {
|
||||
flag := f.Lookup(name)
|
||||
func hasNoOptDefVal(name string, fs *flag.FlagSet) bool {
|
||||
flag := fs.Lookup(name)
|
||||
if flag == nil {
|
||||
return false
|
||||
}
|
||||
|
@ -378,14 +378,15 @@ func hasNoOptDefVal(name string, f *flag.FlagSet) bool {
|
|||
}
|
||||
|
||||
func shortHasNoOptDefVal(name string, fs *flag.FlagSet) bool {
|
||||
result := false
|
||||
fs.VisitAll(func(flag *flag.Flag) {
|
||||
if flag.Shorthand == name && flag.NoOptDefVal != "" {
|
||||
result = true
|
||||
return
|
||||
if len(name) == 0 {
|
||||
return false
|
||||
}
|
||||
})
|
||||
return result
|
||||
|
||||
flag := fs.ShorthandLookup(name[:1])
|
||||
if flag == nil {
|
||||
return false
|
||||
}
|
||||
return flag.NoOptDefVal != ""
|
||||
}
|
||||
|
||||
func stripFlags(args []string, c *Command) []string {
|
||||
|
|
Loading…
Reference in a new issue