|
7 | 7 | "io/fs" |
8 | 8 | "net/mail" |
9 | 9 | "os" |
| 10 | + "strings" |
10 | 11 | "testing" |
11 | 12 |
|
12 | 13 | "github.com/stretchr/testify/require" |
@@ -182,6 +183,49 @@ func TestToTabularMarkdown(t *testing.T) { |
182 | 183 | }) |
183 | 184 | } |
184 | 185 |
|
| 186 | +func TestPrepareCommandsSkipsNestedHelp(t *testing.T) { |
| 187 | + tmpl := tabularTemplate{} |
| 188 | + commands := []*cli.Command{ |
| 189 | + {Name: "help"}, |
| 190 | + { |
| 191 | + Name: "config", |
| 192 | + Commands: []*cli.Command{ |
| 193 | + {Name: "help"}, |
| 194 | + {Name: "sub"}, |
| 195 | + }, |
| 196 | + }, |
| 197 | + } |
| 198 | + |
| 199 | + result := tmpl.PrepareCommands(commands, "app", "", 0) |
| 200 | + require.Len(t, result, 2) |
| 201 | + require.Equal(t, "help", result[0].Name) |
| 202 | + require.Len(t, result[1].SubCommands, 1) |
| 203 | + require.Equal(t, "config sub", result[1].SubCommands[0].Name) |
| 204 | + require.Equal(t, uint(0), result[0].Level) |
| 205 | + require.Equal(t, uint(0), result[1].Level) |
| 206 | + require.Equal(t, uint(1), result[1].SubCommands[0].Level) |
| 207 | +} |
| 208 | + |
| 209 | +func TestPrepareCommandsMarkdownSkipsNestedHelp(t *testing.T) { |
| 210 | + commands := []*cli.Command{ |
| 211 | + {Name: "help"}, |
| 212 | + { |
| 213 | + Name: "config", |
| 214 | + Commands: []*cli.Command{ |
| 215 | + {Name: "help"}, |
| 216 | + {Name: "sub"}, |
| 217 | + }, |
| 218 | + }, |
| 219 | + } |
| 220 | + |
| 221 | + sections := prepareCommands(commands, 0) |
| 222 | + joined := strings.Join(sections, "\n") |
| 223 | + require.Contains(t, joined, "## help\n") |
| 224 | + require.Contains(t, joined, "## config\n") |
| 225 | + require.Contains(t, joined, "### sub\n") |
| 226 | + require.NotContains(t, joined, "### help") |
| 227 | +} |
| 228 | + |
185 | 229 | func TestToTabularMarkdownFailed(t *testing.T) { |
186 | 230 | tpl := MarkdownTabularDocTemplate |
187 | 231 | t.Cleanup(func() { MarkdownTabularDocTemplate = tpl }) |
|
0 commit comments