Skip to content

Commit

Permalink
Merge branch version/0-43-0-RC1 to adopt changes from PR #2902
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Nov 28, 2023
2 parents c027197 + eccb361 commit 733457b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/captain/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (c *Command) Execute(args []string) error {
c.cobra.SetArgs(args)
err := c.cobra.Execute()
c.cobra.SetArgs(nil)
return setupSensibleErrors(err)
return setupSensibleErrors(err, args)
}

func (c *Command) SetExamples(examples ...string) *Command {
Expand Down Expand Up @@ -768,7 +768,7 @@ func (c *Command) argValidator(cobraCmd *cobra.Command, args []string) error {

// setupSensibleErrors inspects an error value for certain errors and returns a
// wrapped error that can be checked and that is localized.
func setupSensibleErrors(err error) error {
func setupSensibleErrors(err error, args []string) error {
if err, ok := err.(error); ok && err == nil {
return nil
}
Expand Down Expand Up @@ -816,10 +816,7 @@ func setupSensibleErrors(err error) error {
}

if pflagErrCmd := pflagCmdErrMsgCmd(errMsg); pflagErrCmd != "" {
return locale.NewInputError(
"command_cmd_no_such_cmd",
"No such command: [NOTICE]{{.V0}}[/RESET]", pflagErrCmd,
)
return locale.NewInputError("command_cmd_no_such_cmd", "", pflagErrCmd)
}

// Cobra error message of the form "accepts at most 0 arg(s), received 1, called at: "
Expand All @@ -830,6 +827,9 @@ func setupSensibleErrors(err error) error {
multilog.Error("Unable to parse cobra error message: %v", err)
return locale.NewInputError("err_cmd_unexpected_arguments", "Unexpected argument(s) given")
}
if max == 0 && received > 0 {
return locale.NewInputError("command_cmd_no_such_cmd", "", args[len(args)-received])
}
return locale.NewInputError(
"err_cmd_too_many_arguments",
"Too many arguments given: {{.V0}} expected, {{.V1}} received",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/locales/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,8 @@ notice_commit_build_script:
command_flag_invalid_value:
other: "Invalid value for {{.V0}} flag: [NOTICE]{{.V1}}[/RESET]"
command_cmd_no_such_cmd:
other: "No such command: [NOTICE]{{.V0}}[/RESET]"
err_cmdtree:
other: Could not run the requested command
err_fetch_languages:
Expand Down

0 comments on commit 733457b

Please sign in to comment.