diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000000000000000000000000000000000000..7f64214d2c3e33847dd6932a0934d833708ac9cc --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,57 @@ +// Copyright © 2019 NAME HERE <EMAIL ADDRESS> +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "fmt" + + "git.psu.edu/swe-golang/buildversion" + "github.com/fatih/color" + "github.com/spf13/cobra" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "displays the software version", + Run: func(cmd *cobra.Command, args []string) { + version := buildversion.Get() + + if version.Version == "" { + color.Red("No build information present") + return + } + + fmt.Printf("Version: %s\n", buildversion.Get().Version) + fmt.Printf("Build Date: %s\n", buildversion.Get().BuildDate) + fmt.Printf("Commit: %s\n", buildversion.Get().Commit) + fmt.Printf("GoVersion: %s\n", buildversion.Get().GoVersion) + fmt.Printf("PipeID: %s\n", buildversion.Get().PipeID) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // versionCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/go.mod b/go.mod index 88d1010e2edfd9f673bd9562fc34dd2e6c9e862c..cecb2955b85a8a64350fe94e3785815193bf6963 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.psu.edu/k8s/devtool go 1.12 require ( + git.psu.edu/swe-golang/buildversion v0.1.0 github.com/BurntSushi/toml v0.3.1 // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect github.com/fatih/color v1.7.0 diff --git a/go.sum b/go.sum index 9cb3c2bbf5a35894c8a00f8ab8a7eac13c6cd462..1ba5ffa3f5c580df0700e6ed83406f713297361d 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +git.psu.edu/swe-golang/buildversion v0.1.0 h1:MA5Sd3m5Uuq+UoH8vwtSX7n/tHLTW7cH7I0884kquSc= +git.psu.edu/swe-golang/buildversion v0.1.0/go.mod h1:3GggCLs0kp53vq0x5DC+ZXLK4dMW+GyUB9wlflz8PmA= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/alecthomas/gometalinter v2.0.11+incompatible h1:ENdXMllZNSVDTJUUVIzBW9CSEpntTrQa76iRsEFLX/M=