()
| 8 | ) |
| 9 | |
| 10 | func newCommandsCommand() *cobra.Command { |
| 11 | return &cobra.Command{ |
| 12 | Use: "commands", |
| 13 | Short: "List all available commands", |
| 14 | RunE: func(cmd *cobra.Command, args []string) error { |
| 15 | catalog := walkCommands(cmd.Root(), "") |
| 16 | |
| 17 | if writer.IsStyled() { |
| 18 | table := newTable(cmd.OutOrStdout()) |
| 19 | table.addRow([]string{"Command", "Description"}) |
| 20 | for _, entry := range catalog { |
| 21 | path, _ := entry["path"].(string) |
| 22 | short, _ := entry["short"].(string) |
| 23 | table.addRow([]string{path, short}) |
| 24 | } |
| 25 | table.print() |
| 26 | return nil |
| 27 | } |
| 28 | |
| 29 | return writeOK(catalog, |
| 30 | output.WithSummary("Available commands"), |
| 31 | ) |
| 32 | }, |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func walkCommands(cmd *cobra.Command, prefix string) []map[string]any { |
| 37 | var result []map[string]any |
no test coverage detected