MCPcopy
hub / github.com/urfave/cli / TestCompletionSubcommandCustomShellComplete

Function TestCompletionSubcommandCustomShellComplete

completion_test.go:423–448  ·  completion_test.go::TestCompletionSubcommandCustomShellComplete
(t *testing.T)

Source from the content-addressed store, hash-verified

421}
422
423func TestCompletionSubcommandCustomShellComplete(t *testing.T) {
424 out := &bytes.Buffer{}
425
426 cmd := &Command{
427 EnableShellCompletion: true,
428 Writer: out,
429 Commands: []*Command{
430 {
431 Name: "index",
432 Commands: []*Command{
433 {
434 Name: "show",
435 ShellComplete: func(ctx context.Context, cmd *Command) {
436 fmt.Fprintln(cmd.Root().Writer, "custom-index")
437 },
438 Action: func(ctx context.Context, cmd *Command) error { return nil },
439 },
440 },
441 },
442 },
443 }
444
445 r := require.New(t)
446 r.NoError(cmd.Run(buildTestContext(t), []string{"foo", "index", "show", completionFlag}))
447 r.Equal("custom-index\n", out.String())
448}
449
450func TestCompletionRunsBeforeChain(t *testing.T) {
451 type contextKey struct{}

Callers

nothing calls this directly

Calls 4

RootMethod · 0.95
RunMethod · 0.95
buildTestContextFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected