|
1 | 1 | package cli
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bytes" |
4 | 5 | "strings"
|
5 | 6 | "testing"
|
6 | 7 |
|
@@ -47,4 +48,51 @@ func TestSynopsisGenerator(t *testing.T) {
|
47 | 48 | if !strings.Contains(syn, "[--]") {
|
48 | 49 | t.Fatal("Synopsis should contain options finalizer")
|
49 | 50 | }
|
| 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 | + } |
50 | 98 | }
|
0 commit comments