Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Add version number, -V and --version

Nick Craig-Wooda81ae3c3f96c
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 <parameters> <parameters...>
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"