Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
test help with double levels
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 3, 2017
1 parent 4e26b97 commit 8d6d9ab
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,55 @@ func TestCLIRun_printCommandHelpSubcommands(t *testing.T) {
}
}

func TestCLIRun_printCommandHelpSubcommandsNestedTwoLevel(t *testing.T) {
testCases := [][]string{
{"--help", "L1"},
{"-h", "L1"},
}

for _, args := range testCases {
command := &MockCommand{
HelpText: "donuts",
}

buf := new(bytes.Buffer)
cli := &CLI{
Args: args,
Commands: map[string]CommandFactory{
"L1": func() (Command, error) {
return command, nil
},
"L1 L2A": func() (Command, error) {
return &MockCommand{SynopsisText: "hi!"}, nil
},
"L1 L2B": func() (Command, error) {
return &MockCommand{SynopsisText: "hi!"}, nil
},
"L1 L2A L3A": func() (Command, error) {
return &MockCommand{SynopsisText: "hi!"}, nil
},
"L1 L2A L3B": func() (Command, error) {
return &MockCommand{SynopsisText: "hi!"}, nil
},
},
HelpWriter: buf,
}

exitCode, err := cli.Run()
if err != nil {
t.Fatalf("err: %s", err)
}

if exitCode != 1 {
t.Fatalf("bad exit code: %d", exitCode)
}

if buf.String() != testCommandHelpSubcommandsTwoLevelOutput {
t.Fatalf("bad: %#v\n\n%s\n\n%s", args, buf.String(), testCommandHelpSubcommandsOutput)
}
}
}

func TestCLIRun_printCommandHelpTemplate(t *testing.T) {
testCases := [][]string{
{"--help", "foo"},
Expand Down Expand Up @@ -596,3 +645,10 @@ Subcommands:
zap hi!
zip hi!
`

const testCommandHelpSubcommandsTwoLevelOutput = `donuts
Subcommands:
L2A hi!
L2B hi!
`

0 comments on commit 8d6d9ab

Please sign in to comment.