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>
`
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)
}
import (
"flag"
"fmt"
+ "io"
"os"
"strconv"
"strings"
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()
}
func usage() {
fmt.Fprintf(os.Stderr, "usage: link [options] main.o\n")
- objabi.Flagprint(2)
+ objabi.Flagprint(os.Stderr)
Exit(2)
}