MCPcopy Index your code
hub / github.com/ddev/ddev / ExecOnHostOrService

Method ExecOnHostOrService

pkg/ddevapp/ddevapp.go:2633–2667  ·  view source on GitHub ↗
(service string, cmd string)

Source from the content-addressed store, hash-verified

2631}
2632
2633func (app *DdevApp) ExecOnHostOrService(service string, cmd string) error {
2634 var err error
2635 // Handle case on host
2636 if service == "host" {
2637 cwd, _ := os.Getwd()
2638 err = os.Chdir(app.GetAppRoot())
2639 if err != nil {
2640 return fmt.Errorf("unable to GetAppRoot: %v", err)
2641 }
2642 bashPath := "bash"
2643 if nodeps.IsWindows() {
2644 bashPath = util.FindBashPath()
2645 if bashPath == "" {
2646 return fmt.Errorf("unable to find bash.exe on Windows")
2647 }
2648 }
2649
2650 args := []string{
2651 "-c",
2652 cmd,
2653 }
2654
2655 _ = app.DockerEnv()
2656 err = exec.RunInteractiveCommand(bashPath, args)
2657 _ = os.Chdir(cwd)
2658 } else { // handle case in container
2659 _, _, err = app.Exec(
2660 &ExecOpts{
2661 Service: service,
2662 Cmd: cmd,
2663 Tty: isatty.IsTerminal(os.Stdin.Fd()),
2664 })
2665 }
2666 return err
2667}
2668
2669// Logs returns logs for a site's given container.
2670// See docker.LogsOptions for more information about valid tailLines values.

Callers 8

PullMethod · 0.80
PushMethod · 0.80
UploadDBMethod · 0.80
UploadFilesMethod · 0.80
doFilesPullCommandMethod · 0.80
getDatabaseBackupsMethod · 0.80
importDatabaseBackupMethod · 0.80
doFilesImportMethod · 0.80

Calls 8

GetAppRootMethod · 0.95
DockerEnvMethod · 0.95
ExecMethod · 0.95
IsWindowsFunction · 0.92
FindBashPathFunction · 0.92
RunInteractiveCommandFunction · 0.92
ChdirMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected