positionalSignature extracts the positional-argument part of cmd.Use, e.g. " " from "set " and " " from "rule [flags] ". Bracketed fields are not placeholders the user types, so "[flags]" and inline enumerations such as "[bash|zsh]" are dropped; enumerated v
(cmd *cobra.Command)
| 79 | // types, so "[flags]" and inline enumerations such as "[bash|zsh]" are dropped; |
| 80 | // enumerated values are reported from ValidArgs instead. |
| 81 | func positionalSignature(cmd *cobra.Command) string { |
| 82 | fields := strings.Fields(cmd.Use) |
| 83 | if len(fields) < 2 { |
| 84 | return "" |
| 85 | } |
| 86 | |
| 87 | parts := make([]string, 0, len(fields)-1) |
| 88 | for _, f := range fields[1:] { |
| 89 | if strings.HasPrefix(f, "<") { |
| 90 | parts = append(parts, f) |
| 91 | } |
| 92 | } |
| 93 | return strings.Join(parts, " ") |
| 94 | } |
| 95 | |
| 96 | // validArgNames strips the "name\tdescription" form Cobra allows in ValidArgs, |
| 97 | // keeping only the value the user is expected to type. The split matches the one |
no outgoing calls