From e22b43ef387a186baacbe1020cbda5cc2635f12a Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 26 Jul 2015 16:22:32 +0200 Subject: [PATCH] Fix: Move version info to flag instead of command --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 8982f2c..136f220 100644 --- a/main.go +++ b/main.go @@ -14,8 +14,9 @@ import ( var ( cfg = struct { - Delete bool - Public bool + Delete bool + Public bool + PrintVersion bool }{} version = "dev" ) @@ -39,18 +40,17 @@ func main() { Use: "s3sync ", Short: "Sync files from to ", Run: execSync, - } - - app.AddCommand(&cobra.Command{ - Use: "version", - Short: "Returns the current version of s3sync", - Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("s3sync %s\n", version) + PreRun: func(cmd *cobra.Command, args []string) { + if cfg.PrintVersion { + fmt.Printf("s3sync %s\n", version) + os.Exit(0) + } }, - }) + } app.Flags().BoolVarP(&cfg.Public, "public", "P", false, "Make files public when syncing to S3") app.Flags().BoolVarP(&cfg.Delete, "delete", "d", false, "Delete files on remote not existing on local") + app.Flags().BoolVarP(&cfg.PrintVersion, "version", "v", false, "Print version and quit") app.Execute() }