Browse Source

Merge pull request #1062 from gtardif/fix_cli_moby_command_detect

Make Moby command detection (based on help output) more robust.
Nicolas De loof 5 năm trước cách đây
mục cha
commit
10a19b1159
1 tập tin đã thay đổi với 2 bổ sung4 xóa
  1. 2 4
      cli/mobycli/exec.go

+ 2 - 4
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