mirror of
https://github.com/docker/compose.git
synced 2025-07-22 21:24:38 +02:00
Merge pull request #201 from docker/fix_delegate_errors
Do not delegate to old cli if cobra fails before invoking the PreRun or SetHelp hook.
This commit is contained in:
commit
07a29e2d0e
15
cli/main.go
15
cli/main.go
@ -60,8 +60,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
runningOwnCommand bool
|
ownCommands = map[string]struct{}{
|
||||||
ownCommands = map[string]struct{}{
|
|
||||||
"context": {},
|
"context": {},
|
||||||
"login": {},
|
"login": {},
|
||||||
"serve": {},
|
"serve": {},
|
||||||
@ -100,8 +99,7 @@ func main() {
|
|||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
runningOwnCommand = isOwnCommand(cmd)
|
if !isOwnCommand(cmd) {
|
||||||
if !runningOwnCommand {
|
|
||||||
dockerclassic.Exec(cmd.Context())
|
dockerclassic.Exec(cmd.Context())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -125,8 +123,7 @@ func main() {
|
|||||||
|
|
||||||
helpFunc := root.HelpFunc()
|
helpFunc := root.HelpFunc()
|
||||||
root.SetHelpFunc(func(cmd *cobra.Command, args []string) {
|
root.SetHelpFunc(func(cmd *cobra.Command, args []string) {
|
||||||
runningOwnCommand = isOwnCommand(cmd)
|
if !isOwnCommand(cmd) {
|
||||||
if !runningOwnCommand {
|
|
||||||
dockerclassic.Exec(cmd.Context())
|
dockerclassic.Exec(cmd.Context())
|
||||||
}
|
}
|
||||||
helpFunc(cmd, args)
|
helpFunc(cmd, args)
|
||||||
@ -163,9 +160,11 @@ func main() {
|
|||||||
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
||||||
ctx = store.WithContextStore(ctx, s)
|
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
|
// 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)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
func (s *E2eSuite) TestClassicLoginWithparameters() {
|
||||||
output, err := s.NewDockerCommand("login", "-u", "nouser", "-p", "wrongpasword").Exec()
|
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"))
|
Expect(output).To(ContainSubstring("Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user