No specific case for windows, always resolve binary name before executing command

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-11-05 17:05:39 +01:00
parent 3936826673
commit 41a1553dab
1 changed files with 5 additions and 10 deletions

View File

@ -22,7 +22,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"runtime"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -61,14 +60,10 @@ func mustDelegateToMoby(ctxType string) bool {
// Exec delegates to com.docker.cli if on moby context // Exec delegates to com.docker.cli if on moby context
func Exec(root *cobra.Command) { func Exec(root *cobra.Command) {
execBinary := ComDockerCli execBinary, err := LookPath(ComDockerCli)
if runtime.GOOS == "windows" { // workaround for windows issue https://github.com/golang/go/issues/38736 if err != nil {
var err error fmt.Fprintln(os.Stderr, err)
execBinary, err = LookPath(ComDockerCli) os.Exit(1)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
} }
cmd := exec.Command(execBinary, os.Args[1:]...) cmd := exec.Command(execBinary, os.Args[1:]...)
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
@ -93,7 +88,7 @@ func Exec(root *cobra.Command) {
} }
}() }()
err := cmd.Run() err = cmd.Run()
childExit <- true childExit <- true
if err != nil { if err != nil {
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus) metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus)