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)
| 116 | // short forms are checked — pflag's Lookup treats single-character |
| 117 | // names as shorthand and ShorthandLookup as the lookup for them. |
| 118 | func 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 |