cmd: avoid printing redundant newlines

For golang/go#49350

Change-Id: Ic566112ff8a8707998b461d2b99fca852f2972f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/361716
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Zvonimir Pavlinovic 2021-11-05 11:42:54 -07:00
parent 0c60b7c5c2
commit 2cdcc60405
7 changed files with 11 additions and 9 deletions

View File

@ -166,7 +166,7 @@ var stdout io.Writer = os.Stdout
func doCallgraph(dir, gopath, algo, format string, tests bool, args []string) error {
if len(args) == 0 {
fmt.Fprintln(os.Stderr, Usage)
fmt.Fprint(os.Stderr, Usage)
return nil
}

View File

@ -42,8 +42,8 @@ Finally, to generate modified source code with coverage annotations
`
func usage() {
fmt.Fprintln(os.Stderr, usageMessage)
fmt.Fprintln(os.Stderr, "Flags:")
fmt.Fprint(os.Stderr, usageMessage)
fmt.Fprintln(os.Stderr, "\nFlags:")
flag.PrintDefaults()
fmt.Fprintln(os.Stderr, "\n Only one of -html, -func, or -mode may be set.")
os.Exit(2)

View File

@ -59,7 +59,8 @@ func doMain() error {
args := flag.Args()
if *helpFlag {
fmt.Fprint(os.Stderr, eg.Help)
help := eg.Help // hide %s from vet
fmt.Fprint(os.Stderr, help)
os.Exit(2)
}

View File

@ -83,7 +83,7 @@ func main() {
}
if *helpFlag || *fromFlag == "" || *toFlag == "" {
fmt.Println(Usage)
fmt.Print(Usage)
return
}

View File

@ -46,7 +46,7 @@ func main() {
}
if *helpFlag || (*offsetFlag == "" && *fromFlag == "" && *toFlag == "") {
fmt.Println(rename.Usage)
fmt.Print(rename.Usage)
return
}

View File

@ -167,7 +167,8 @@ files to include for such packages.
`
func usage() {
fmt.Fprintln(os.Stderr, usageString)
fmt.Fprint(os.Stderr, usageString)
fmt.Fprintln(os.Stderr)
flag.PrintDefaults()
os.Exit(2)
}

View File

@ -105,8 +105,8 @@ Example: describe syntax at offset 530 in this file (an import spec):
`
func printHelp() {
fmt.Fprintln(os.Stderr, helpMessage)
fmt.Fprintln(os.Stderr, "Flags:")
fmt.Fprint(os.Stderr, helpMessage)
fmt.Fprintln(os.Stderr, "\nFlags:")
flag.PrintDefaults()
}