diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 6333bbcb..15d6cd46 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -37,17 +37,27 @@ var ( showVersion bool confDir string trace string - profiler string verbose bool ) +const ( + usage = "syncthing [options]" + extraUsage = `The following environemnt variables can be set to facilitate debugging: + + STPROFILER Set to a listen address such as "127.0.0.1:9090" to start the + profiler with HTTP access. + + STTRACE A comma separated string of facilities to trace. The valid + facility strings: + - "scanner" (the file change scanner)` +) + func main() { flag.StringVar(&confDir, "home", getDefaultConfDir(), "Set configuration directory") flag.StringVar(&trace, "debug.trace", "", "(connect,net,idx,file,pull)") - flag.StringVar(&profiler, "debug.profiler", "", "(addr)") flag.BoolVar(&showVersion, "version", false, "Show version") flag.BoolVar(&verbose, "v", false, "Be more verbose") - flag.Usage = usageFor(flag.CommandLine, "syncthing [options]") + flag.Usage = usageFor(flag.CommandLine, usage, extraUsage) flag.Parse() if len(os.Getenv("STRESTART")) > 0 { @@ -156,8 +166,9 @@ func main() { var dir = expandTilde(cfg.Repositories[0].Directory) - if len(profiler) > 0 { + if profiler := os.Getenv("STPROFILER"); len(profiler) > 0 { go func() { + debugln("Starting profiler on", profiler) err := http.ListenAndServe(profiler, nil) if err != nil { warnln(err) diff --git a/cmd/syncthing/usage.go b/cmd/syncthing/usage.go index cfd1f303..cc4a8431 100644 --- a/cmd/syncthing/usage.go +++ b/cmd/syncthing/usage.go @@ -22,18 +22,14 @@ func optionTable(w io.Writer, rows [][]string) { tw.Flush() } -func usageFor(fs *flag.FlagSet, usage string) func() { +func usageFor(fs *flag.FlagSet, usage string, extra string) func() { return func() { var b bytes.Buffer b.WriteString("Usage:\n " + usage + "\n") var options [][]string fs.VisitAll(func(f *flag.Flag) { - var dash = "-" - if len(f.Name) > 1 { - dash = "--" - } - var opt = " " + dash + f.Name + var opt = " -" + f.Name if f.DefValue != "false" { opt += "=" + f.DefValue @@ -48,5 +44,9 @@ func usageFor(fs *flag.FlagSet, usage string) func() { } fmt.Println(b.String()) + + if len(extra) > 0 { + fmt.Println(extra) + } } }