MCPcopy
hub / github.com/perkeep/perkeep / runAsNewCommand

Function runAsNewCommand

pkg/cmdmain/cmdmain.go:338–352  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

336// cmd must implement the ExecRunner interface. The executable must be a binary of
337// a program that runs Main.
338func 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.

Callers 1

MainFunction · 0.85

Calls 5

ErrorfFunction · 0.85
shiftFlagsFunction · 0.85
newCopyEnvFunction · 0.85
runExecFunction · 0.70
LookPathMethod · 0.65

Tested by

no test coverage detected