mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Fixes #10760 The coder CLI quietly accepts any subcommand arguments and silently swallows them. Currently: ```sh ❯ coder | head -n5 coder v2.3.3+e491217 USAGE: coder [global-flags] <subcommand> ``` ```sh ❯ coder idontexist | head -n5 coder v2.3.3+e491217 USAGE: coder [global-flags] <subcommand> ``` Now help output will not be show when there is an unknown subcommand error. Instead users will be given the command for the help output. ```sh ❯ coder idontexist Encountered an error running "coder", see "coder --help" for more information error: unrecognized subcommand "idontexist" ``` ```sh ❯ coder iexistbut idontexist Encountered an error running "coder iexistbut", see "coder iexistbut --help" for more information error: unrecognized subcommand "idontexist" ``` Also this stuff: `Encountered an error running "coder iexistbut"... ` gets written to `os.Stdout` in `prettyErrorFormatter{w: os.Stderr, verbose: r.verbose}`, not sure how to test that output.
This commit is contained in:
+5
-2
@@ -1196,10 +1196,13 @@ func formatMultiError(from string, multi []error, opts *formatOpts) string {
|
||||
// formatter and add it to cliHumanFormatError function.
|
||||
func formatRunCommandError(err *serpent.RunCommandError, opts *formatOpts) string {
|
||||
var str strings.Builder
|
||||
_, _ = str.WriteString(pretty.Sprint(headLineStyle(), fmt.Sprintf("Encountered an error running %q", err.Cmd.FullName())))
|
||||
_, _ = str.WriteString(pretty.Sprint(headLineStyle(),
|
||||
fmt.Sprintf(
|
||||
`Encountered an error running %q, see "%s --help" for more information`,
|
||||
err.Cmd.FullName(), err.Cmd.FullName())))
|
||||
_, _ = str.WriteString(pretty.Sprint(headLineStyle(), "\nerror: "))
|
||||
|
||||
msgString, special := cliHumanFormatError("", err.Err, opts)
|
||||
_, _ = str.WriteString("\n")
|
||||
if special {
|
||||
_, _ = str.WriteString(msgString)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user