Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit fc21528

Browse files
committed
mobycli: update approach for finding cli command to use
1. Use path from env variable `$DOCKER_COM_DOCKER_CLI` 2. Use path formed from parent directory of current process joined with `com.docker.cli` 3. Look for `com.docker.cli` on $PATH Signed-off-by: Nick Sieger <[email protected]>
1 parent d8b9310 commit fc21528

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

cli/mobycli/exec.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ func mustDelegateToMoby(ctxType string) bool {
6262
return false
6363
}
6464

65-
func comDockerCli() string {
66-
if v := os.Getenv("DOCKER_COM_DOCKER_CLI"); v != "" {
67-
return v
68-
}
69-
return ComDockerCli
70-
}
71-
7265
// Exec delegates to com.docker.cli if on moby context
7366
func Exec(root *cobra.Command) {
7467
childExit := make(chan bool)
@@ -99,20 +92,7 @@ func Exec(root *cobra.Command) {
9992

10093
// RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
10194
func RunDocker(childExit chan bool, args ...string) error {
102-
execBinary := comDockerCli()
103-
if execBinary == ComDockerCli {
104-
var err error
105-
execBinary, err = resolvepath.LookPath(ComDockerCli)
106-
if err != nil {
107-
execBinary = findBinary(ComDockerCli)
108-
if execBinary == "" {
109-
fmt.Fprintln(os.Stderr, err)
110-
fmt.Fprintln(os.Stderr, "Current PATH : "+os.Getenv("PATH"))
111-
os.Exit(1)
112-
}
113-
}
114-
}
115-
cmd := exec.Command(execBinary, args...)
95+
cmd := exec.Command(comDockerCli(), args...)
11696
cmd.Stdin = os.Stdin
11797
cmd.Stdout = os.Stdout
11898
cmd.Stderr = os.Stderr
@@ -142,6 +122,25 @@ func RunDocker(childExit chan bool, args ...string) error {
142122
return cmd.Run()
143123
}
144124

125+
func comDockerCli() string {
126+
if v := os.Getenv("DOCKER_COM_DOCKER_CLI"); v != "" {
127+
return v
128+
}
129+
130+
execBinary := findBinary(ComDockerCli)
131+
if execBinary == "" {
132+
var err error
133+
execBinary, err = resolvepath.LookPath(ComDockerCli)
134+
if err != nil {
135+
fmt.Fprintln(os.Stderr, err)
136+
fmt.Fprintln(os.Stderr, "Current PATH : "+os.Getenv("PATH"))
137+
os.Exit(1)
138+
}
139+
}
140+
141+
return execBinary
142+
}
143+
145144
func findBinary(filename string) string {
146145
currentBinaryPath, err := os.Executable()
147146
if err != nil {

0 commit comments

Comments
 (0)