| 6405 | } |
| 6406 | |
| 6407 | func TestCommand_Walk_ShortCircuit(t *testing.T) { |
| 6408 | subCmd := &Command{Name: "bar"} |
| 6409 | subSubCmd := &Command{Name: "baz"} |
| 6410 | subCmd.Commands = []*Command{subSubCmd} |
| 6411 | |
| 6412 | cmd := &Command{ |
| 6413 | Name: "foo", |
| 6414 | Commands: []*Command{subCmd}, |
| 6415 | } |
| 6416 | |
| 6417 | errWalk := fmt.Errorf("stop") |
| 6418 | var visited []string |
| 6419 | err := cmd.Walk(func(c *Command) error { |
| 6420 | visited = append(visited, c.Name) |
| 6421 | if c.Name == "bar" { |
| 6422 | return errWalk |
| 6423 | } |
| 6424 | return nil |
| 6425 | }) |
| 6426 | assert.ErrorIs(t, err, errWalk) |
| 6427 | assert.Equal(t, []string{"foo", "bar"}, visited) |
| 6428 | } |
| 6429 | |
| 6430 | func TestCommand_Walk_Hidden(t *testing.T) { |
| 6431 | subCmd := &Command{Name: "bar", HideHelp: true} |