mirror of https://github.com/docker/compose.git
Look for docker cli next to the current executable
Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
This commit is contained in:
parent
6bfdfa8947
commit
313de1de4a
|
@ -22,6 +22,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
apicontext "github.com/docker/compose-cli/api/context"
|
apicontext "github.com/docker/compose-cli/api/context"
|
||||||
|
@ -89,9 +90,12 @@ func Exec(root *cobra.Command) {
|
||||||
func RunDocker(childExit chan bool, args ...string) error {
|
func RunDocker(childExit chan bool, args ...string) error {
|
||||||
execBinary, err := resolvepath.LookPath(ComDockerCli)
|
execBinary, err := resolvepath.LookPath(ComDockerCli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
execBinary = findBinary(ComDockerCli)
|
||||||
fmt.Fprintln(os.Stderr, "Current PATH : "+os.Getenv("PATH"))
|
if execBinary == "" {
|
||||||
os.Exit(1)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
fmt.Fprintln(os.Stderr, "Current PATH : "+os.Getenv("PATH"))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cmd := exec.Command(execBinary, args...)
|
cmd := exec.Command(execBinary, args...)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
|
@ -123,6 +127,22 @@ func RunDocker(childExit chan bool, args ...string) error {
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findBinary(filename string) string {
|
||||||
|
currentBinaryPath, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
currentBinaryPath, err = filepath.EvalSymlinks(currentBinaryPath)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
binaryPath := filepath.Join(filepath.Dir(currentBinaryPath), filename)
|
||||||
|
if _, err := os.Stat(binaryPath); err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return binaryPath
|
||||||
|
}
|
||||||
|
|
||||||
// IsDefaultContextCommand checks if the command exists in the classic cli (issues a shellout --help)
|
// IsDefaultContextCommand checks if the command exists in the classic cli (issues a shellout --help)
|
||||||
func IsDefaultContextCommand(dockerCommand string) bool {
|
func IsDefaultContextCommand(dockerCommand string) bool {
|
||||||
cmd := exec.Command(ComDockerCli, dockerCommand, "--help")
|
cmd := exec.Command(ComDockerCli, dockerCommand, "--help")
|
||||||
|
|
Loading…
Reference in New Issue