MCPcopy Create free account
hub / github.com/alecthomas/kong / TestHelpTree

Function TestHelpTree

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

Source from the content-addressed store, hash-verified

281}
282
283func 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
325A test app.
326
327Flags:
328 -h, --help Show context-sensitive help.
329
330Commands:
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
340Run "test-app <command> --help" for more information on a command.

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