From 807b5c11c6b74884d241f8c1b2498dc0aa7a1208 Mon Sep 17 00:00:00 2001 From: corka149 Date: Thu, 22 Oct 2020 17:43:59 +0200 Subject: [PATCH] Added version CMD --- cmd/version.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cmd/version.go diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..b76f4c6 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,51 @@ +/* +Copyright © 2020 Sebastian Ziemann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package cmd + +import ( + "runtime" + + "github.com/spf13/cobra" + jww "github.com/spf13/jwalterweatherman" +) + +var ( + major = 3 + minor = 0 + patch = 0 + buildHash = "" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Prints version of timed and quit", + Long: "Prints version of timed and quit", + Run: func(cmd *cobra.Command, args []string) { + osArch := runtime.GOOS + "/" + runtime.GOARCH + jww.FEEDBACK.Printf("%d.%d.%d (%s - %s)", major, minor, patch, osArch, buildHash) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +}