From 999853a8242368bece88ba37169efcc438ff6382 Mon Sep 17 00:00:00 2001 From: Erick Kramer Date: Thu, 23 May 2024 20:21:43 +0200 Subject: [PATCH] feat: Add version command --- README.md | 1 + cmd/version.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 cmd/version.go diff --git a/README.md b/README.md index a562dd9..337b896 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Available Commands: switch Switch repository version sync Synchronize all found repositories. validate Validate a .repos file + version Print the version number ``` Each of the available commands have their own help with information about their usage and available flags (e.g. `rv help import`). diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..97eb268 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,36 @@ +/* +Copyright © 2024 Erick Kramer +*/ +package cmd + +import ( + "fmt" + "ripvcs/utils" + + "github.com/spf13/cobra" +) + +var ( + // These variables should be set using ldflags during the build + Version = "v0.1.1" + Commit = "39dfff5" + BuildDate = "25.05.2024" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number", + Run: func(cmd *cobra.Command, args []string) { + utils.PrintSection("ripvcs (rv)") + utils.PrintSeparator() + fmt.Printf("%sVersion:%s %s\n", utils.BlueColor, utils.ResetColor, Version) + fmt.Printf("%sCommit:%s %s\n", utils.BlueColor, utils.ResetColor, Commit) + fmt.Printf("%sBuild Date:%s %s\n", utils.BlueColor, utils.ResetColor, BuildDate) + utils.PrintSeparator() + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +}