| 6386 | } |
| 6387 | |
| 6388 | func TestCommand_Walk(t *testing.T) { |
| 6389 | subCmd := &Command{Name: "bar"} |
| 6390 | subSubCmd := &Command{Name: "baz"} |
| 6391 | subCmd.Commands = []*Command{subSubCmd} |
| 6392 | |
| 6393 | cmd := &Command{ |
| 6394 | Name: "foo", |
| 6395 | Commands: []*Command{subCmd}, |
| 6396 | } |
| 6397 | |
| 6398 | var visited []string |
| 6399 | err := cmd.Walk(func(c *Command) error { |
| 6400 | visited = append(visited, c.Name) |
| 6401 | return nil |
| 6402 | }) |
| 6403 | require.NoError(t, err) |
| 6404 | assert.Equal(t, []string{"foo", "bar", "baz"}, visited) |
| 6405 | } |
| 6406 | |
| 6407 | func TestCommand_Walk_ShortCircuit(t *testing.T) { |
| 6408 | subCmd := &Command{Name: "bar"} |