From a8403241e49170ec0235bc4f18464e99e51a4a9c Mon Sep 17 00:00:00 2001 From: Guillaume Lours Date: Wed, 15 Apr 2020 16:55:30 +0200 Subject: [PATCH] Add default shellout to engine if no context specified Improve CLI documentation Signed-off-by: Guillaume Lours --- cmd/main.go | 30 +++++++++++++++++++++++++----- context/flags.go | 4 ++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 3e247a46e..56508950e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -30,7 +30,9 @@ package main import ( "fmt" "os" + "os/exec" "path/filepath" + "sort" "github.com/docker/api/context" "github.com/sirupsen/logrus" @@ -61,25 +63,43 @@ func main() { context.ConfigFlag, context.ContextFlag, } + + app.Before = func(clix *cli.Context) error { if clix.GlobalBool("debug") { logrus.SetLevel(logrus.DebugLevel) } - - context, err := context.GetContext() + ctx, err := context.GetContext() if err != nil { - return err + logrus.Fatal(err) } - fmt.Println(context.Metadata.Type) - // TODO select backend based on context.Metadata.Type or delegate to legacy CLI if == "Moby" + if ctx.Metadata.Type == "Moby" { + shellOutToDefaultEngine() + os.Exit(0) + } + // TODO select backend based on context.Metadata.Type return nil } app.Commands = []cli.Command{ contextCommand, exampleCommand, } + + sort.Sort(cli.FlagsByName(app.Flags)) + sort.Sort(cli.CommandsByName(app.Commands)) + if err := app.Run(os.Args); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } + +func shellOutToDefaultEngine() { + cmd :=exec.Command("/Applications/Docker.app/Contents/Resources/bin/docker", os.Args[1:]...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + logrus.Fatal(err) + } +} diff --git a/context/flags.go b/context/flags.go index b335cbc4a..ce9d411fb 100644 --- a/context/flags.go +++ b/context/flags.go @@ -17,7 +17,7 @@ var ( ConfigDir string ConfigFlag = cli.StringFlag{ Name: "config", - Usage: "Location of client config files", + Usage: "Location of client config files `DIRECTORY`", EnvVar: "DOCKER_CONFIG", Value: filepath.Join(homedir.Get(), configFileDir), Destination: &ConfigDir, @@ -26,7 +26,7 @@ var ( ContextName string ContextFlag = cli.StringFlag{ Name: "context, c", - Usage: `Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")`, + Usage: "Name of the context `CONTEXT` to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with \"docker context use\")", EnvVar: "DOCKER_CONTEXT", Destination: &ContextName, }