Commit 7ddd467e authored by Daniel Martí's avatar Daniel Martí

cmd/compile: print usage to stderr for consistency

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: default avatarMatthew Dempsky <mdempsky@google.com>
parent ddb503be
......@@ -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)
}
......
......@@ -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()
}
......
......@@ -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)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment