Files
boringproxy/main.go
Martin Tournoij a67253c55a Add usage information
Before not giving any command didn't really give much feedback beyond
"invalid arguments". This adds a basic usage message, and tells people
that you can use "boringproxy server -h".

I moved the "Starting up" log message because otherwise that would get
printed when asking for "server -h".

I also added error checks for the flag parsing; I think this isn't
*strictly* needed, but I remember running in to problems once by
omitting it (although I've forgotten what that problem was, exactly).
2021-01-05 22:04:08 +08:00

38 lines
687 B
Go

package main
import (
"fmt"
"os"
)
const usage = `Usage: %s [command] [flags]
Commands:
server Start a new server.
client Connect to a server.
Use "%[1]s command -h" for a list of flags for the command.
`
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, os.Args[0]+": Need a command")
fmt.Printf(usage, os.Args[0])
os.Exit(1)
}
command := os.Args[1]
switch command {
case "help", "-h", "--help", "-help":
fmt.Printf(usage, os.Args[0])
case "server":
Listen()
case "client":
client := NewBoringProxyClient()
client.RunPuppetClient()
default:
fmt.Fprintln(os.Stderr, os.Args[0]+": Invalid command "+command)
os.Exit(1)
}
}