Skip to content

Commit b0de627

Browse files
committed
wip: show subcommand ShortHelp bug with test
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]>
1 parent bb36028 commit b0de627

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

cli/helptext_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"bytes"
45
"strings"
56
"testing"
67

@@ -47,4 +48,51 @@ func TestSynopsisGenerator(t *testing.T) {
4748
if !strings.Contains(syn, "[--]") {
4849
t.Fatal("Synopsis should contain options finalizer")
4950
}
51+
if strings.Contains(syn, "For more information about each command") {
52+
t.Fatal("Synopsis should not contain subcommands")
53+
}
54+
}
55+
56+
func TestShortHelp(t *testing.T) {
57+
// ShortHelp behaves differently depending on whether the command is the root or not.
58+
root := &cmds.Command{
59+
Subcommands: map[string]*cmds.Command{
60+
"ls": {
61+
Helptext: cmds.HelpText{
62+
ShortDescription: `
63+
Displays the contents of an IPFS or IPNS object(s) at the given path.
64+
`},
65+
},
66+
},
67+
}
68+
// Ask for the help text for the ls command which has no subcommands
69+
path := []string{"ls"}
70+
buf := new(bytes.Buffer)
71+
ShortHelp("ipfs", root, path, buf)
72+
helpText := buf.String()
73+
t.Logf("Short help text: %s", helpText)
74+
if strings.Contains(helpText, "For more information about each command") {
75+
t.Fatal("ShortHelp should not contain subcommand info")
76+
}
77+
}
78+
79+
func TestLongHelp(t *testing.T) {
80+
root := &cmds.Command{
81+
Subcommands: map[string]*cmds.Command{
82+
"ls": {
83+
Helptext: cmds.HelpText{
84+
ShortDescription: `
85+
Displays the contents of an IPFS or IPNS object(s) at the given path.
86+
`},
87+
},
88+
},
89+
}
90+
path := []string{"ls"}
91+
buf := new(bytes.Buffer)
92+
LongHelp("ipfs", root, path, buf)
93+
helpText := buf.String()
94+
t.Logf("Long help text: %s", helpText)
95+
if strings.Contains(helpText, "For more information about each command") {
96+
t.Fatal("LongHelp should not contain subcommand info")
97+
}
5098
}

0 commit comments

Comments
 (0)