]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: print usage to stderr for consistency
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 24 Dec 2017 16:50:28 +0000 (16:50 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 13 Feb 2018 21:11:55 +0000 (21:11 +0000)
All the other tools and commands print the usage text to standard error.
"go tool compile" was the odd one out, so fix it.

While at it, make objabi.Flagprint a bit more Go-like with an io.Writer
instead of a file descriptor, which is likely a leftover from the C
days.

Fixes #23234.

Change-Id: I9abf2e79461e61c8c8bfaee2c6bf8faf26e0e6c3
Reviewed-on: https://go-review.googlesource.com/85418
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/main.go
src/cmd/internal/objabi/flag.go
src/cmd/link/internal/ld/lib.go

index f1591c16d2deb7547c52790508587c0ac28480eb..802e02896de59f59f8b69746ceef3fa8b14633bf 100644 (file)
@@ -94,8 +94,8 @@ Key "pctab" supports values:
 `
 
 func usage() {
-       fmt.Printf("usage: compile [options] file.go...\n")
-       objabi.Flagprint(1)
+       fmt.Fprintf(os.Stderr, "usage: compile [options] file.go...\n")
+       objabi.Flagprint(os.Stderr)
        Exit(2)
 }
 
index 1bd4bc9063ae15f4312a8b13b6e0433ae665a9fd..d0522c8f4314ac3ab8f4bf4841e72fa9ca88bb68 100644 (file)
@@ -7,6 +7,7 @@ package objabi
 import (
        "flag"
        "fmt"
+       "io"
        "os"
        "strconv"
        "strings"
@@ -20,10 +21,8 @@ func Flagfn1(name, usage string, f func(string)) {
        flag.Var(fn1(f), name, usage)
 }
 
-func Flagprint(fd int) {
-       if fd == 1 {
-               flag.CommandLine.SetOutput(os.Stdout)
-       }
+func Flagprint(w io.Writer) {
+       flag.CommandLine.SetOutput(w)
        flag.PrintDefaults()
 }
 
index 6dcaf64122f918c85d9e3bcb46d59e60dae38672..bfff5209a6b779638af33816982cebe0311596b2 100644 (file)
@@ -1953,7 +1953,7 @@ func stkprint(ctxt *Link, ch *chain, limit int) {
 
 func usage() {
        fmt.Fprintf(os.Stderr, "usage: link [options] main.o\n")
-       objabi.Flagprint(2)
+       objabi.Flagprint(os.Stderr)
        Exit(2)
 }