From 17e78d6f7e63c3cd51e94e1260e5f395739f359e Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 8 Jan 2014 14:37:33 +0100 Subject: [PATCH] Option to show version (fixes #24) --- main.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 54c151eb..1b42c15e 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "compress/gzip" "crypto/tls" + "fmt" "log" "net" "net/http" @@ -21,18 +22,19 @@ import ( ) type Options struct { - ConfDir string `short:"c" long:"cfg" description:"Configuration directory" default:"~/.syncthing" value-name:"DIR"` - Listen string `short:"l" long:"listen" description:"Listen address" default:":22000" value-name:"ADDR"` - ReadOnly bool `short:"r" long:"ro" description:"Repository is read only"` - Rehash bool `long:"rehash" description:"Ignore cache and rehash all files in repository"` - NoDelete bool `long:"no-delete" description:"Never delete files"` - NoSymlinks bool `long:"no-symlinks" description:"Don't follow first level symlinks in the repo"` - NoStats bool `long:"no-stats" description:"Don't print model and connection statistics"` - NoGUI bool `long:"no-gui" description:"Don't start GUI"` - GUIAddr string `long:"gui-addr" description:"GUI listen address" default:"127.0.0.1:8080" value-name:"ADDR"` - Discovery DiscoveryOptions `group:"Discovery Options"` - Advanced AdvancedOptions `group:"Advanced Options"` - Debug DebugOptions `group:"Debugging Options"` + ConfDir string `short:"c" long:"cfg" description:"Configuration directory" default:"~/.syncthing" value-name:"DIR"` + Listen string `short:"l" long:"listen" description:"Listen address" default:":22000" value-name:"ADDR"` + ReadOnly bool `short:"r" long:"ro" description:"Repository is read only"` + Rehash bool `long:"rehash" description:"Ignore cache and rehash all files in repository"` + NoDelete bool `long:"no-delete" description:"Never delete files"` + NoSymlinks bool `long:"no-symlinks" description:"Don't follow first level symlinks in the repo"` + NoStats bool `long:"no-stats" description:"Don't print model and connection statistics"` + NoGUI bool `long:"no-gui" description:"Don't start GUI"` + GUIAddr string `long:"gui-addr" description:"GUI listen address" default:"127.0.0.1:8080" value-name:"ADDR"` + ShowVersion bool `short:"v" long:"version" description:"Show version"` + Discovery DiscoveryOptions `group:"Discovery Options"` + Advanced AdvancedOptions `group:"Advanced Options"` + Debug DebugOptions `group:"Debugging Options"` } type DebugOptions struct { @@ -71,8 +73,14 @@ var ( func main() { _, err := flags.Parse(&opts) if err != nil { + fatalln(err) + } + + if opts.ShowVersion { + fmt.Println(Version) os.Exit(0) } + if len(opts.Debug.TraceModel) > 0 || opts.Debug.LogSource { logger = log.New(os.Stderr, "", log.Lshortfile|log.Ldate|log.Ltime|log.Lmicroseconds) }