diff --git a/cli/helptext.go b/cli/helptext.go index 5458bb2b..22230476 100644 --- a/cli/helptext.go +++ b/cli/helptext.go @@ -110,9 +110,11 @@ const shortHelpFormat = `USAGE {{end}}{{if .Subcommands}} SUBCOMMANDS {{.Subcommands}} -{{end}}{{if .MoreHelp}} {{.Indent}}For more information about each command, use: {{.Indent}}'{{.Path}} --help' +{{end}}{{if .MoreHelp}} +{{.Indent}}for more information about this command, use: +{{.Indent}}'{{.Path}} --help' {{end}} ` diff --git a/cli/helptext_test.go b/cli/helptext_test.go index 7e135683..a9163dde 100644 --- a/cli/helptext_test.go +++ b/cli/helptext_test.go @@ -1,6 +1,7 @@ package cli import ( + "bytes" "strings" "testing" @@ -48,3 +49,47 @@ func TestSynopsisGenerator(t *testing.T) { t.Fatal("Synopsis should contain options finalizer") } } + +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") + } +}