MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / flagExists

Function flagExists

internal/cmdhelp/example_validation.go:118–136  ·  view source on GitHub ↗

flagExists reports whether `name` is a known flag on cmd or any of its ancestors (covers persistent / inherited flags). Both long and short forms are checked — pflag's Lookup treats single-character names as shorthand and ShorthandLookup as the lookup for them.

(cmd *cobra.Command, name string)

Source from the content-addressed store, hash-verified

116// short forms are checked — pflag's Lookup treats single-character
117// names as shorthand and ShorthandLookup as the lookup for them.
118func flagExists(cmd *cobra.Command, name string) bool {
119 for c := cmd; c != nil; c = c.Parent() {
120 if c.Flags().Lookup(name) != nil {
121 return true
122 }
123 if c.PersistentFlags().Lookup(name) != nil {
124 return true
125 }
126 if len(name) == 1 {
127 if c.Flags().ShorthandLookup(name) != nil {
128 return true
129 }
130 if c.PersistentFlags().ShorthandLookup(name) != nil {
131 return true
132 }
133 }
134 }
135 return false
136}
137
138// shellSplit tokenizes a command line in a POSIX-ish way: whitespace
139// separates tokens, double-quotes group, single-quotes group (no

Callers 1

validateExampleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected