From 50dfbebef55c3e646ad23c3befa0f01bfb2220b8 Mon Sep 17 00:00:00 2001 From: Daniel Menet Date: Fri, 13 Dec 2019 13:25:24 +0100 Subject: [PATCH] general: added version subcommand --- main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.go b/main.go index 5e6d48e..95207d8 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,10 @@ import ( ) var ( + version string + commit string + date string + rootConfigPath string rootQuiet bool rootSingularityPath string @@ -45,6 +49,8 @@ func init() { rootCmd.AddCommand(deduceSingularityCmd) rootCmd.AddCommand(listSingularityKeysCmd) + + rootCmd.AddCommand(versionCmd) } var rootCmd = &cobra.Command{ @@ -155,6 +161,23 @@ var deduceSingularityCmd = &cobra.Command{ }, } +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version info", + Run: func(cmd *cobra.Command, args []string) { + if version == "" { + version = "dirty" + } + if commit == "" { + commit = "dirty" + } + if date == "" { + date = "unknown" + } + fmt.Printf("Version: %s\nCommit: %s\nBuild Date: %s\n", version, commit, date) + }, +} + func main() { err := rootCmd.Execute() exitOnErr(err)