Skip to content

Commit

Permalink
wip: show subcommand ShortHelp bug with test
Browse files Browse the repository at this point in the history
ShortHelp always shows the subcommand help prompt even if there are no subcommands.

Add a test to demo it.

License: MIT
Signed-off-by: Oli Evans <[email protected]>
  • Loading branch information
olizilla committed Oct 22, 2020
1 parent bb36028 commit b0de627
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cli/helptext_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"bytes"
"strings"
"testing"

Expand Down Expand Up @@ -47,4 +48,51 @@ func TestSynopsisGenerator(t *testing.T) {
if !strings.Contains(syn, "[--]") {
t.Fatal("Synopsis should contain options finalizer")
}
if strings.Contains(syn, "For more information about each command") {
t.Fatal("Synopsis should not contain subcommands")
}
}

func TestShortHelp(t *testing.T) {
// ShortHelp behaves differently depending on whether the command is the root or not.
root := &cmds.Command{
Subcommands: map[string]*cmds.Command{
"ls": {
Helptext: cmds.HelpText{
ShortDescription: `
Displays the contents of an IPFS or IPNS object(s) at the given path.
`},
},
},
}
// Ask for the help text for the ls command which has no subcommands
path := []string{"ls"}
buf := new(bytes.Buffer)
ShortHelp("ipfs", root, path, buf)
helpText := buf.String()
t.Logf("Short help text: %s", helpText)
if strings.Contains(helpText, "For more information about each command") {
t.Fatal("ShortHelp should not contain subcommand info")
}
}

func TestLongHelp(t *testing.T) {
root := &cmds.Command{
Subcommands: map[string]*cmds.Command{
"ls": {
Helptext: cmds.HelpText{
ShortDescription: `
Displays the contents of an IPFS or IPNS object(s) at the given path.
`},
},
},
}
path := []string{"ls"}
buf := new(bytes.Buffer)
LongHelp("ipfs", root, path, buf)
helpText := buf.String()
t.Logf("Long help text: %s", helpText)
if strings.Contains(helpText, "For more information about each command") {
t.Fatal("LongHelp should not contain subcommand info")
}
}

0 comments on commit b0de627

Please sign in to comment.