Skip to content

Commit

Permalink
Be careful what you wish for
Browse files Browse the repository at this point in the history
  • Loading branch information
awh committed Aug 20, 2015
1 parent e1feefc commit 6f93a65
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions prog/weaver/main.go
Expand Up @@ -3,7 +3,7 @@ package main
import (
"crypto/sha256"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
_ "net/http/pprof"
Expand All @@ -27,6 +27,18 @@ import (

var version = "(unreleased version)"

type rewriter struct {
writer io.Writer
}

func (r rewriter) Write(p []byte) (int, error) {
if string(p) == "See '/home/weave/weaver --help'.\n" {
return fmt.Fprintln(r.writer, "See 'weave help'.")
} else {
return r.writer.Write(p)
}
}

func main() {
procs := runtime.NumCPU()
// packet sniffing can block an OS thread, so we need one thread
Expand Down Expand Up @@ -63,8 +75,8 @@ func main() {
dnsClientTimeout time.Duration
)

fs := mflag.NewFlagSet("", mflag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
fs := mflag.NewFlagSet("", mflag.ExitOnError)
fs.SetOutput(rewriter{os.Stderr})
fs.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
fs.IntVar(&config.Port, []string{"#port", "-port"}, weave.Port, "router port")
fs.IntVar(&protocolMinVersion, []string{"-min-protocol-version"}, weave.ProtocolMinVersion, "minimum weave protocol version")
Expand All @@ -90,9 +102,7 @@ func main() {
fs.IntVar(&dnsTTL, []string{"-dns-ttl"}, nameserver.DefaultTTL, "TTL for DNS request from our domain")
fs.DurationVar(&dnsClientTimeout, []string{"-dns-fallback-timeout"}, nameserver.DefaultClientTimeout, "timeout for fallback DNS requests")

if err := fs.Parse(os.Args[1:]); err != nil {
Log.Fatalf("Incorrect usage: %s", err)
}
fs.Parse(os.Args[1:])
SetLogLevel(logLevel)
peers = fs.Args()

Expand Down

0 comments on commit 6f93a65

Please sign in to comment.