(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestGetCommandsRecursivelyIncludesNestedCommands(t *testing.T) { |
| 13 | root := &cobra.Command{Use: "algolia", Short: "Algolia CLI"} |
| 14 | one := &cobra.Command{Use: "one", Short: "Level one"} |
| 15 | two := &cobra.Command{Use: "two", Short: "Level two"} |
| 16 | three := &cobra.Command{Use: "three", Short: "Level three"} |
| 17 | four := &cobra.Command{ |
| 18 | Use: "four", |
| 19 | Short: "Level four", |
| 20 | RunE: func(*cobra.Command, []string) error { |
| 21 | return nil |
| 22 | }, |
| 23 | } |
| 24 | |
| 25 | three.AddCommand(four) |
| 26 | two.AddCommand(three) |
| 27 | one.AddCommand(two) |
| 28 | root.AddCommand(one) |
| 29 | |
| 30 | commands := getCommands(root) |
| 31 | require.Len(t, commands, 1) |
| 32 | require.Len(t, commands[0].SubCommands, 1) |
| 33 | require.Len(t, commands[0].SubCommands[0].SubCommands, 1) |
| 34 | require.Len(t, commands[0].SubCommands[0].SubCommands[0].SubCommands, 1) |
| 35 | require.Equal( |
| 36 | t, |
| 37 | "algolia one two three four", |
| 38 | commands[0].SubCommands[0].SubCommands[0].SubCommands[0].Name, |
| 39 | ) |
| 40 | } |
| 41 | |
| 42 | func TestGenMdxTreeWritesNestedCommandPages(t *testing.T) { |
| 43 | root := &cobra.Command{Use: "algolia", Short: "Algolia CLI"} |
nothing calls this directly
no test coverage detected