diff --git a/cli/main.go b/cli/main.go index ef84a534c..10e50f134 100644 --- a/cli/main.go +++ b/cli/main.go @@ -60,8 +60,7 @@ import ( ) var ( - runningOwnCommand bool - ownCommands = map[string]struct{}{ + ownCommands = map[string]struct{}{ "context": {}, "login": {}, "serve": {}, @@ -100,8 +99,7 @@ func main() { SilenceErrors: true, SilenceUsage: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - runningOwnCommand = isOwnCommand(cmd) - if !runningOwnCommand { + if !isOwnCommand(cmd) { dockerclassic.Exec(cmd.Context()) } return nil @@ -125,8 +123,7 @@ func main() { helpFunc := root.HelpFunc() root.SetHelpFunc(func(cmd *cobra.Command, args []string) { - runningOwnCommand = isOwnCommand(cmd) - if !runningOwnCommand { + if !isOwnCommand(cmd) { dockerclassic.Exec(cmd.Context()) } helpFunc(cmd, args) @@ -163,9 +160,11 @@ func main() { ctx = apicontext.WithCurrentContext(ctx, currentContext) ctx = store.WithContextStore(ctx, s) - if err = root.ExecuteContext(ctx); err != nil { + err = root.ExecuteContext(ctx) + if err != nil { // Context should always be handled by new CLI - if runningOwnCommand { + requiredCmd, _, _ := root.Find(os.Args[1:]) + if requiredCmd != nil && isOwnCommand(requiredCmd) { fmt.Fprintln(os.Stderr, err) os.Exit(1) } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index c85858637..2d250c583 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -76,6 +76,14 @@ func (s *E2eSuite) TestContextLegacy() { }) } +func (s *E2eSuite) TestContextCreateParseErrorDoesNotDelegateToLegacy() { + It("should dispay new cli error when parsing context create flags", func() { + _, err := s.NewDockerCommand("context", "create", "--aci-subscription-id", "titi").Exec() + Expect(err.Error()).NotTo(ContainSubstring("unknown flag")) + Expect(err.Error()).To(ContainSubstring("accepts 2 arg(s), received 0")) + }) +} + func (s *E2eSuite) TestClassicLoginWithparameters() { output, err := s.NewDockerCommand("login", "-u", "nouser", "-p", "wrongpasword").Exec() Expect(output).To(ContainSubstring("Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password"))