runAsNewCommand runs the executable specified by cmd's LookPath, which means cmd must implement the ExecRunner interface. The executable must be a binary of a program that runs Main.
(cmd CommandRunner, mode string)
| 336 | // cmd must implement the ExecRunner interface. The executable must be a binary of |
| 337 | // a program that runs Main. |
| 338 | func runAsNewCommand(cmd CommandRunner, mode string) { |
| 339 | execCmd, ok := cmd.(ExecRunner) |
| 340 | if !ok { |
| 341 | panic(fmt.Sprintf("%v does not implement ExecRunner", mode)) |
| 342 | } |
| 343 | cmdPath, err := execCmd.LookPath() |
| 344 | if err != nil { |
| 345 | Errorf("Error: %v\n", err) |
| 346 | Exit(2) |
| 347 | } |
| 348 | allArgs := shiftFlags(mode) |
| 349 | if err := runExec(cmdPath, allArgs, newCopyEnv()); err != nil { |
| 350 | panic(fmt.Sprintf("running %v should have ended with an os.Exit, and not leave us with that error: %v", cmdPath, err)) |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | // shiftFlags prepends all the arguments (global flags) passed before the given |
| 355 | // mode to the list of arguments after that mode, and returns that list. |
no test coverage detected