(cmd *cobra.Command)
| 50 | } |
| 51 | |
| 52 | func newCommand(cmd *cobra.Command) Command { |
| 53 | categoryFlagSet := cmdutil.NewCategoryFlagSet(cmd.NonInheritedFlags()) |
| 54 | // Make sure the command description ends with a period. |
| 55 | if !strings.HasSuffix(cmd.Short, ".") { |
| 56 | cmd.Short += "." |
| 57 | } |
| 58 | |
| 59 | command := Command{ |
| 60 | Name: cmd.CommandPath(), |
| 61 | Description: cmd.Short, |
| 62 | Usage: cmd.UseLine(), |
| 63 | Aliases: cmd.Aliases, |
| 64 | Examples: cmd.Example, |
| 65 | RunInWebCLI: false, |
| 66 | CommandType: commandType(cmd), |
| 67 | Annotations: cmd.Annotations, |
| 68 | } |
| 69 | if value, ok := cmd.Annotations["runInWebCLI"]; ok && value != "" { |
| 70 | command.RunInWebCLI = true |
| 71 | } |
| 72 | |
| 73 | flags := make(map[string][]Flag) |
| 74 | |
| 75 | if len(categoryFlagSet.Categories) > 0 { |
| 76 | for _, categoryName := range categoryFlagSet.SortedCategoryNames() { |
| 77 | flags[categoryName] = newFlags(categoryFlagSet.Categories[categoryName]) |
| 78 | } |
| 79 | if categoryFlagSet.Others.HasAvailableFlags() { |
| 80 | flags["Other flags"] = newFlags(categoryFlagSet.Others) |
| 81 | } |
| 82 | } else { |
| 83 | if categoryFlagSet.Others.HasAvailableFlags() { |
| 84 | flags["Flags"] = newFlags(categoryFlagSet.Others) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if categoryFlagSet.Print.HasAvailableFlags() { |
| 89 | flags["Output formatting flags"] = newFlags(categoryFlagSet.Print) |
| 90 | } |
| 91 | command.Flags = flags |
| 92 | |
| 93 | return command |
| 94 | } |
| 95 | |
| 96 | func commandType(cmd *cobra.Command) string { |
| 97 | switch cmd.Name() { |
no test coverage detected