diff --git a/cli/main.go b/cli/main.go index c7f6bcaf4..418765501 100644 --- a/cli/main.go +++ b/cli/main.go @@ -34,6 +34,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/docker/api/cli/cmd" apicontext "github.com/docker/api/context" @@ -73,8 +74,9 @@ func isContextCommand(cmd *cobra.Command) bool { func main() { var opts mainOpts root := &cobra.Command{ - Use: "docker", - Long: "docker for the 2020s", + Use: "docker", + Long: "docker for the 2020s", + SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if !isContextCommand(cmd) { execMoby(cmd.Context()) @@ -123,6 +125,10 @@ func main() { ctx = store.WithContextStore(ctx, s) if err = root.ExecuteContext(ctx); err != nil { + if strings.Contains(err.Error(), "unknown command") { + execMoby(ctx) + } + fmt.Println(err) os.Exit(1) } } diff --git a/context/store/store.go b/context/store/store.go index d693b90a1..6f864d978 100644 --- a/context/store/store.go +++ b/context/store/store.go @@ -58,8 +58,8 @@ func ContextStore(ctx context.Context) Store { // Store type Store interface { - // Get returns the context with with name, it returns an error if the - // context doesn't exist + // Get returns the context with name, it returns an error if the context + // doesn't exist Get(name string) (*Metadata, error) // Create creates a new context, it returns an error if a context with the // same name exists already. diff --git a/context/store/store_test.go b/context/store/store_test.go index 43c96b47c..fd331695c 100644 --- a/context/store/store_test.go +++ b/context/store/store_test.go @@ -29,7 +29,6 @@ package store import ( _ "crypto/sha256" - "fmt" "io/ioutil" "os" "testing" @@ -78,7 +77,6 @@ func TestGet(t *testing.T) { m, ok := meta.Metadata.(TypeContext) assert.Equal(t, ok, true) - fmt.Printf("%#v\n", meta) assert.Equal(t, "description", m.Description) assert.Equal(t, "type", m.Type) })