From a81ae3c3f96c9c7e129baa234014a32a6eb0c39b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 24 Apr 2014 17:59:05 +0100 Subject: [PATCH] Add version number, -V and --version --- rclone.go | 9 +++++++-- rclonetest/rclonetest.go | 9 +++++++-- rclonetest/version.go | 3 +++ version.go | 3 +++ 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 rclonetest/version.go create mode 100644 version.go diff --git a/rclone.go b/rclone.go index c1544b48a..2357a3193 100644 --- a/rclone.go +++ b/rclone.go @@ -27,6 +27,7 @@ var ( // Flags cpuprofile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file") statsInterval = pflag.DurationP("stats", "", time.Minute*1, "Interval to print stats") + version = pflag.BoolP("version", "V", false, "Print the version number") ) type Command struct { @@ -193,13 +194,13 @@ var Commands = []Command{ // syntaxError prints the syntax func syntaxError() { - fmt.Fprintf(os.Stderr, `Sync files and directories to and from local and remote object stores + fmt.Fprintf(os.Stderr, `Sync files and directories to and from local and remote object stores - %s. Syntax: [options] subcommand Subcommands: -`) +`, Version) for i := range Commands { cmd := &Commands[i] fmt.Fprintf(os.Stderr, " %s %s\n", cmd.Name, cmd.ArgsHelp) @@ -299,6 +300,10 @@ func StartStats() { func main() { ParseFlags() + if *version { + fmt.Printf("rclone %s\n", Version) + os.Exit(0) + } command, args := ParseCommand() // Make source and destination fs diff --git a/rclonetest/rclonetest.go b/rclonetest/rclonetest.go index 3eb982d36..c6003ca17 100644 --- a/rclonetest/rclonetest.go +++ b/rclonetest/rclonetest.go @@ -26,6 +26,7 @@ import ( // Globals var ( localName, remoteName string + version = pflag.BoolP("version", "V", false, "Print the version number") ) // Represents an item for checking @@ -257,7 +258,7 @@ func TestRmdir(flocal, fremote fs.Fs) { } func syntaxError() { - fmt.Fprintf(os.Stderr, `Test rclone with a remote to find bugs in either. + fmt.Fprintf(os.Stderr, `Test rclone with a remote to find bugs in either - %s. Syntax: [options] remote: @@ -266,7 +267,7 @@ directory under it and perform tests on it, deleting it at the end. Options: -`) +`, Version) pflag.PrintDefaults() } @@ -282,6 +283,10 @@ func cleanTempDir() { func main() { pflag.Usage = syntaxError pflag.Parse() + if *version { + fmt.Printf("rclonetest %s\n", Version) + os.Exit(0) + } fs.LoadConfig() rand.Seed(time.Now().UnixNano()) args := pflag.Args() diff --git a/rclonetest/version.go b/rclonetest/version.go new file mode 100644 index 000000000..0890ea308 --- /dev/null +++ b/rclonetest/version.go @@ -0,0 +1,3 @@ +package main + +const Version = "v0.95" diff --git a/version.go b/version.go new file mode 100644 index 000000000..0890ea308 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package main + +const Version = "v0.95"