MCPcopy Index your code
hub / github.com/devspace-sh/devspace / RunListCommands

Method RunListCommands

cmd/list/commands.go:44–111  ·  view source on GitHub ↗

RunListCommands runs the list command logic

(f factory.Factory, cobraCmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

42
43// RunListCommands runs the list command logic
44func (cmd *commandsCmd) RunListCommands(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
45 logger := f.GetLog()
46 // Set config root
47 configLoader, err := f.NewConfigLoader("")
48 if err != nil {
49 return err
50 }
51 configExists, err := configLoader.SetDevSpaceRoot(logger)
52 if err != nil {
53 return err
54 }
55 if !configExists {
56 return errors.New(message.ConfigNotFound)
57 }
58
59 // Parse commands
60 commandsInterface, err := configLoader.LoadWithParser(context.Background(), nil, nil, loader.NewCommandsParser(), nil, logger)
61 if err != nil {
62 return err
63 }
64 commands := commandsInterface.Config().Commands
65
66 // Specify the table column names
67 headerColumnNames := []string{
68 "Section",
69 "Name",
70 "Description",
71 }
72
73 sections := map[string][][]string{}
74 for _, command := range commands {
75 if command.Internal {
76 continue
77 }
78
79 sections[command.Section] = append(sections[command.Section], []string{
80 command.Name,
81 command.Description,
82 })
83 }
84
85 allRows := [][]string{}
86 for section, r := range sections {
87 sort.Slice(r, func(i, j int) bool {
88 return r[i][0] < r[j][0]
89 })
90 if section == "" && len(sections) == 1 {
91 headerColumnNames = []string{"Name", "Description"}
92 allRows = r
93 break
94 }
95
96 for _, ri := range r {
97 allRows = append(allRows, []string{
98 section,
99 ri[0],
100 ri[1],
101 })

Callers 1

newCommandsCmdFunction · 0.95

Calls 7

SetDevSpaceRootMethod · 0.95
LoadWithParserMethod · 0.95
NewCommandsParserFunction · 0.92
PrintTableWithOptionsFunction · 0.92
GetLogMethod · 0.65
NewConfigLoaderMethod · 0.65
ConfigMethod · 0.65

Tested by

no test coverage detected