MCPcopy Create free account
hub / github.com/algolia/cli / newCommand

Function newCommand

internal/docs/docs.go:52–94  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

50}
51
52func 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
96func commandType(cmd *cobra.Command) string {
97 switch cmd.Name() {

Callers 2

getCommandsFunction · 0.85
describeCommandFunction · 0.85

Calls 4

SortedCategoryNamesMethod · 0.95
NewCategoryFlagSetFunction · 0.92
commandTypeFunction · 0.85
newFlagsFunction · 0.85

Tested by

no test coverage detected