mirror of https://github.com/spf13/cobra.git
Use pflag.ShorthandLookup
This commit is contained in:
parent
8f0203be89
commit
4061f41c9a
25
command.go
25
command.go
|
@ -11,8 +11,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//Package cobra is a commander providing a simple interface to create powerful modern CLI interfaces.
|
// Package cobra is a commander providing a simple interface to create powerful modern CLI interfaces.
|
||||||
//In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.
|
// In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -369,8 +369,8 @@ func (c *Command) HelpTemplate() string {
|
||||||
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
|
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasNoOptDefVal(name string, f *flag.FlagSet) bool {
|
func hasNoOptDefVal(name string, fs *flag.FlagSet) bool {
|
||||||
flag := f.Lookup(name)
|
flag := fs.Lookup(name)
|
||||||
if flag == nil {
|
if flag == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -378,14 +378,15 @@ func hasNoOptDefVal(name string, f *flag.FlagSet) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func shortHasNoOptDefVal(name string, fs *flag.FlagSet) bool {
|
func shortHasNoOptDefVal(name string, fs *flag.FlagSet) bool {
|
||||||
result := false
|
if len(name) == 0 {
|
||||||
fs.VisitAll(func(flag *flag.Flag) {
|
return false
|
||||||
if flag.Shorthand == name && flag.NoOptDefVal != "" {
|
}
|
||||||
result = true
|
|
||||||
return
|
flag := fs.ShorthandLookup(name[:1])
|
||||||
}
|
if flag == nil {
|
||||||
})
|
return false
|
||||||
return result
|
}
|
||||||
|
return flag.NoOptDefVal != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripFlags(args []string, c *Command) []string {
|
func stripFlags(args []string, c *Command) []string {
|
||||||
|
|
Loading…
Reference in New Issue