Browse Source

http2/h2i: Handle invalid usage more idiomatically.

I believe it is more idiomatic to use exit code 2 for flag parsing
errors and invalid usage cases.

It's also not needed to do os.Exit inside usage since flag handling
code does it anyway; usage should only print usage text.

Change-Id: I0fe2047e3fd01489d32dfb8fde49ce7829439687
Reviewed-on: https://go-review.googlesource.com/19774
Reviewed-by: Blake Mizerany <blake.mizerany@gmail.com>
Dmitri Shuralyov 9 years ago
parent
commit
4599ae7937
1 changed files with 1 additions and 1 deletions
  1. 1 1
      http2/h2i/h2i.go

+ 1 - 1
http2/h2i/h2i.go

@@ -78,7 +78,6 @@ var commands = map[string]command{
 func usage() {
 func usage() {
 	fmt.Fprintf(os.Stderr, "Usage: h2i <hostname>\n\n")
 	fmt.Fprintf(os.Stderr, "Usage: h2i <hostname>\n\n")
 	flag.PrintDefaults()
 	flag.PrintDefaults()
-	os.Exit(1)
 }
 }
 
 
 // withPort adds ":443" if another port isn't already present.
 // withPort adds ":443" if another port isn't already present.
@@ -111,6 +110,7 @@ func main() {
 	flag.Parse()
 	flag.Parse()
 	if flag.NArg() != 1 {
 	if flag.NArg() != 1 {
 		usage()
 		usage()
+		os.Exit(2)
 	}
 	}
 	log.SetFlags(0)
 	log.SetFlags(0)