فهرست منبع

fix signal passing to mobycli

Signed-off-by: aiordache <[email protected]>
aiordache 5 سال پیش
والد
کامیت
d1b8bcb2c7
8فایلهای تغییر یافته به همراه17 افزوده شده و 20 حذف شده
  1. 2 1
      cli/cmd/context/create.go
  2. 2 1
      cli/cmd/context/inspect.go
  3. 2 1
      cli/cmd/context/ls.go
  4. 2 1
      cli/cmd/login/login.go
  5. 2 1
      cli/cmd/logout/logout.go
  6. 2 1
      cli/cmd/version.go
  7. 1 1
      cli/main.go
  8. 4 13
      cli/mobycli/exec.go

+ 2 - 1
cli/cmd/context/create.go

@@ -70,7 +70,8 @@ $ docker context create my-context --description "some description" --docker "ho
 		Use:   "create CONTEXT",
 		Short: "Create new context",
 		RunE: func(cmd *cobra.Command, args []string) error {
-			return mobycli.ExecCmd(cmd)
+			mobycli.Exec()
+			return nil
 		},
 		Long: longHelp,
 	}

+ 2 - 1
cli/cmd/context/inspect.go

@@ -27,7 +27,8 @@ func inspectCommand() *cobra.Command {
 		Use:   "inspect",
 		Short: "Display detailed information on one or more contexts",
 		RunE: func(cmd *cobra.Command, args []string) error {
-			return mobycli.ExecCmd(cmd)
+			mobycli.Exec()
+			return nil
 		},
 	}
 	// flags matching delegated command in moby cli

+ 2 - 1
cli/cmd/context/ls.go

@@ -69,7 +69,8 @@ func runList(cmd *cobra.Command, opts lsOpts) error {
 		return err
 	}
 	if opts.format != "" {
-		return mobycli.ExecCmd(cmd)
+		mobycli.Exec()
+		return nil
 	}
 
 	ctx := cmd.Context()

+ 2 - 1
cli/cmd/login/login.go

@@ -56,7 +56,8 @@ func runLogin(cmd *cobra.Command, args []string) error {
 		backend := args[0]
 		return errors.New("unknown backend type for cloud login: " + backend)
 	}
-	return mobycli.ExecCmd(cmd)
+	mobycli.Exec()
+	return nil
 }
 
 func cloudLogin(cmd *cobra.Command, backendType string, params interface{}) error {

+ 2 - 1
cli/cmd/logout/logout.go

@@ -21,5 +21,6 @@ func Command() *cobra.Command {
 }
 
 func runLogout(cmd *cobra.Command, args []string) error {
-	return mobycli.ExecCmd(cmd)
+	mobycli.Exec()
+	return nil
 }

+ 2 - 1
cli/cmd/version.go

@@ -51,7 +51,8 @@ func runVersion(cmd *cobra.Command, version string) error {
 	// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
 	// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
 	if versionResult == nil {
-		return mobycli.ExecCmd(cmd)
+		mobycli.Exec()
+		return nil
 	}
 	var s string = string(versionResult)
 	fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration  "+displayedVersion+"\n Version:", 1))

+ 1 - 1
cli/main.go

@@ -151,7 +151,7 @@ func main() {
 
 	// --host and --version should immediately be forwarded to the original cli
 	if opts.Host != "" || opts.Version {
-		mobycli.Exec(ctx)
+		mobycli.Exec()
 	}
 
 	if opts.Config == "" {

+ 4 - 13
cli/mobycli/exec.go

@@ -23,8 +23,6 @@ import (
 	"os/exec"
 	"strings"
 
-	"github.com/spf13/cobra"
-
 	apicontext "github.com/docker/api/context"
 	"github.com/docker/api/context/store"
 )
@@ -43,7 +41,7 @@ func ExecIfDefaultCtxType(ctx context.Context) {
 	currentCtx, err := s.Get(currentContext)
 	// Only run original docker command if the current context is not ours.
 	if err != nil || mustDelegateToMoby(currentCtx.Type()) {
-		Exec(ctx)
+		Exec()
 	}
 }
 
@@ -57,11 +55,12 @@ func mustDelegateToMoby(ctxType string) bool {
 }
 
 // Exec delegates to com.docker.cli if on moby context
-func Exec(ctx context.Context) {
-	cmd := exec.CommandContext(ctx, ComDockerCli, os.Args[1:]...)
+func Exec() {
+	cmd := exec.Command(ComDockerCli, os.Args[1:]...)
 	cmd.Stdin = os.Stdin
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
+
 	if err := cmd.Run(); err != nil {
 		if exiterr, ok := err.(*exec.ExitError); ok {
 			os.Exit(exiterr.ExitCode())
@@ -72,14 +71,6 @@ func Exec(ctx context.Context) {
 	os.Exit(0)
 }
 
-// ExecCmd delegates the cli command to com.docker.cli. The error is never
-// returned (process will exit with docker classic exit code), the return type
-// is to make it easier to use with cobra commands
-func ExecCmd(command *cobra.Command) error {
-	Exec(command.Context())
-	return nil
-}
-
 // IsDefaultContextCommand checks if the command exists in the classic cli (issues a shellout --help)
 func IsDefaultContextCommand(dockerCommand string) bool {
 	cmd := exec.Command(ComDockerCli, dockerCommand, "--help")