(t *testing.T)
| 281 | } |
| 282 | |
| 283 | func TestHelpTree(t *testing.T) { |
| 284 | var cli struct { |
| 285 | One struct { |
| 286 | Thing struct { |
| 287 | Arg string `arg help:"argument"` |
| 288 | } `cmd help:"subcommand thing"` |
| 289 | Other struct { |
| 290 | Other string `arg help:"other arg"` |
| 291 | } `arg help:"subcommand other"` |
| 292 | } `cmd help:"subcommand one" group:"Group A" aliases:"un,uno"` // Groups are ignored in trees |
| 293 | |
| 294 | Two struct { |
| 295 | Three threeArg `arg help:"Sub-sub-arg."` |
| 296 | |
| 297 | Four struct{} `cmd help:"Sub-sub-command." aliases:"for,fore"` |
| 298 | } `cmd help:"Another subcommand."` |
| 299 | } |
| 300 | |
| 301 | w := bytes.NewBuffer(nil) |
| 302 | exited := false |
| 303 | app := mustNew(t, &cli, |
| 304 | kong.Name("test-app"), |
| 305 | kong.Description("A test app."), |
| 306 | kong.Writers(w, w), |
| 307 | kong.ConfigureHelp(kong.HelpOptions{ |
| 308 | Tree: true, |
| 309 | Indenter: kong.LineIndenter, |
| 310 | }), |
| 311 | kong.Exit(func(int) { |
| 312 | exited = true |
| 313 | panic(true) // Panic to fake "exit". |
| 314 | }), |
| 315 | ) |
| 316 | |
| 317 | t.Run("Full", func(t *testing.T) { |
| 318 | panicsTrue(t, func() { |
| 319 | _, err := app.Parse([]string{"--help"}) |
| 320 | assert.NoError(t, err) |
| 321 | }) |
| 322 | assert.True(t, exited) |
| 323 | expected := `Usage: test-app <command> |
| 324 | |
| 325 | A test app. |
| 326 | |
| 327 | Flags: |
| 328 | -h, --help Show context-sensitive help. |
| 329 | |
| 330 | Commands: |
| 331 | one (un,uno) subcommand one |
| 332 | - thing subcommand thing |
| 333 | - <arg> argument |
| 334 | - <other> subcommand other |
| 335 | |
| 336 | two Another subcommand. |
| 337 | - <three> Sub-sub-arg. |
| 338 | - four (for,fore) Sub-sub-command. |
| 339 | |
| 340 | Run "test-app <command> --help" for more information on a command. |
nothing calls this directly
no test coverage detected