]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.21] cmd/go: missing name in failed command error
authorMauri de Souza Meneguzzo <mauri870@gmail.com>
Wed, 2 Aug 2023 13:47:16 +0000 (13:47 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 2 Aug 2023 15:53:43 +0000 (15:53 +0000)
Fixed the error reporting for an unknown command to
preserve the name when displaying the error message.

Fixes #61604

Change-Id: I13defb84e61265ab48ab514e9d4f1626a4a3f758
GitHub-Last-Rev: 5d2889c60ceb3f43bb63b6641ecbcca08b7cd365
GitHub-Pull-Request: golang/go#61607
Reviewed-on: https://go-review.googlesource.com/c/go/+/513555
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/515278
Auto-Submit: David Chase <drchase@google.com>

src/cmd/go/main.go
src/cmd/go/testdata/script/go_badcmd.txt [new file with mode: 0644]

index 2898c68049659acc9ae4d3dc55eca68a1ea4f398..7b73642b5a21ff51e15663da16ba0ec941d9958e 100644 (file)
@@ -175,7 +175,11 @@ func main() {
                if used > 0 {
                        helpArg += " " + strings.Join(args[:used], " ")
                }
-               fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cfg.CmdName, helpArg)
+               cmdName := cfg.CmdName
+               if cmdName == "" {
+                       cmdName = args[0]
+               }
+               fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cmdName, helpArg)
                base.SetExitStatus(2)
                base.Exit()
        }
diff --git a/src/cmd/go/testdata/script/go_badcmd.txt b/src/cmd/go/testdata/script/go_badcmd.txt
new file mode 100644 (file)
index 0000000..661375a
--- /dev/null
@@ -0,0 +1,2 @@
+! go asdf
+stderr '^go asdf: unknown command'