From f55823b70f5505d7b27b40a1c791c1008429f48b Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 15 Dec 2020 12:01:27 +0100 Subject: [PATCH] Make Moby command detection (based on help output) more robust. It seems some tabs have been replaced by spaces in CLI 20.10. Covered with e2e test TestUnsupportedCommand. We need to install docker CLI ourselves in Github actions nodes. Signed-off-by: Guillaume Tardif --- cli/mobycli/exec.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cli/mobycli/exec.go b/cli/mobycli/exec.go index 15f875091..c46637ed2 100644 --- a/cli/mobycli/exec.go +++ b/cli/mobycli/exec.go @@ -22,7 +22,7 @@ import ( "os" "os/exec" "os/signal" - "strings" + "regexp" "github.com/spf13/cobra" @@ -112,9 +112,7 @@ func IsDefaultContextCommand(dockerCommand string) bool { if e != nil { fmt.Println(e) } - output := string(b) - contains := strings.Contains(output, "Usage:\tdocker "+dockerCommand) - return contains + return regexp.MustCompile("Usage:\\s*docker\\s*" + dockerCommand).Match(b) } // ExecSilent executes a command and do redirect output to stdOut, return output