Start implements CLIRunner.
(tb testing.TB, ctx context.Context, args []string, env map[string]string)
| 28 | |
| 29 | // Start implements CLIRunner. |
| 30 | func (e *CLIInProcRunner) Start(tb testing.TB, ctx context.Context, args []string, env map[string]string) (stdout, stderr io.Reader, wait func() error, interrupt func(os.Signal)) { |
| 31 | tb.Helper() |
| 32 | |
| 33 | a := cli.NewApp() |
| 34 | a.DangerousCommands = "enabled" |
| 35 | |
| 36 | envPrefix := fmt.Sprintf("T%v_", atomic.AddInt32(envPrefixCounter, 1)) |
| 37 | a.SetEnvNamePrefixForTesting(envPrefix) |
| 38 | |
| 39 | kpapp := kingpin.New("test", "test") |
| 40 | |
| 41 | if e.CustomizeApp != nil { |
| 42 | e.CustomizeApp(a, kpapp) |
| 43 | } |
| 44 | |
| 45 | e.mu.Lock() |
| 46 | stdin := e.nextCommandStdin |
| 47 | e.nextCommandStdin = nil |
| 48 | e.mu.Unlock() |
| 49 | |
| 50 | for k, v := range env { |
| 51 | os.Setenv(envPrefix+k, v) |
| 52 | } |
| 53 | |
| 54 | return a.RunSubcommand(ctx, kpapp, stdin, args) |
| 55 | } |
| 56 | |
| 57 | // SetNextStdin sets the stdin to be used on next command execution. |
| 58 | func (e *CLIInProcRunner) SetNextStdin(stdin io.Reader) { |
nothing calls this directly
no test coverage detected