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)
| 90 | // types, so "[flags]" and inline enumerations such as "[bash|zsh]" are dropped; |
| 91 | // enumerated values are reported from ValidArgs instead. |
| 92 | func positionalSignature(cmd *cobra.Command) string { |
| 93 | fields := strings.Fields(cmd.Use) |
| 94 | if len(fields) < 2 { |
| 95 | return "" |
| 96 | } |
| 97 | |
| 98 | parts := make([]string, 0, len(fields)-1) |
| 99 | for _, f := range fields[1:] { |
| 100 | if strings.HasPrefix(f, "<") { |
| 101 | parts = append(parts, f) |
| 102 | } |
| 103 | } |
| 104 | return strings.Join(parts, " ") |
| 105 | } |
| 106 | |
| 107 | // validArgNames strips the "name\tdescription" form Cobra allows in ValidArgs, |
| 108 | // keeping only the value the user is expected to type. The split matches the one |
no outgoing calls