MCPcopy
hub / github.com/alecthomas/kong / TestHelpCompactNoExpand

Function TestHelpCompactNoExpand

help_test.go:376–461  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

374}
375
376func TestHelpCompactNoExpand(t *testing.T) {
377 var cli struct {
378 One struct {
379 Thing struct {
380 Arg string `arg help:"argument"`
381 } `cmd help:"subcommand thing"`
382 Other struct {
383 Other string `arg help:"other arg"`
384 } `arg help:"subcommand other"`
385 } `cmd help:"subcommand one" group:"Group A" aliases:"un,uno"` // Groups are ignored in trees
386
387 Two struct {
388 Three threeArg `arg help:"Sub-sub-arg."`
389
390 Four struct{} `cmd help:"Sub-sub-command." aliases:"for,fore"`
391 } `cmd help:"Another subcommand."`
392 }
393
394 w := bytes.NewBuffer(nil)
395 exited := false
396 app := mustNew(t, &cli,
397 kong.Name("test-app"),
398 kong.Description("A test app."),
399 kong.Writers(w, w),
400 kong.ConfigureHelp(kong.HelpOptions{
401 Compact: true,
402 NoExpandSubcommands: true,
403 }),
404 kong.Exit(func(int) {
405 exited = true
406 panic(true) // Panic to fake "exit".
407 }),
408 )
409
410 t.Run("Full", func(t *testing.T) {
411 panicsTrue(t, func() {
412 _, err := app.Parse([]string{"--help"})
413 assert.NoError(t, err)
414 })
415 assert.True(t, exited)
416 expected := `Usage: test-app <command>
417
418A test app.
419
420Flags:
421 -h, --help Show context-sensitive help.
422
423Commands:
424 two Another subcommand.
425
426Group A
427 one (un,uno) subcommand one
428
429Run "test-app <command> --help" for more information on a command.
430`
431 if expected != w.String() {
432 t.Errorf("help command returned:\n%v\n\nwant:\n%v", w.String(), expected)
433 }

Callers

nothing calls this directly

Calls 11

NameFunction · 0.92
DescriptionFunction · 0.92
WritersFunction · 0.92
ConfigureHelpFunction · 0.92
ExitFunction · 0.92
mustNewFunction · 0.85
panicsTrueFunction · 0.85
ErrorfMethod · 0.80
RunMethod · 0.45
ParseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…