(t *testing.T)
| 421 | } |
| 422 | |
| 423 | func 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 | |
| 450 | func TestCompletionRunsBeforeChain(t *testing.T) { |
| 451 | type contextKey struct{} |
nothing calls this directly
no test coverage detected