From 47c279c30290f372039105db109dcc99ac922ead Mon Sep 17 00:00:00 2001 From: schmiddim Date: Mon, 17 Jun 2024 14:21:37 +0200 Subject: [PATCH] Version Info --- README.md | 2 +- cmd/version.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 cmd/version.go diff --git a/README.md b/README.md index fe7627d..d2d389e 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ export POMODORO_API_KEY=your_api_key export POMODORO_ENDPOINT=http://localhost:8 ## Create a quick Release ```shell -TAG=0.0.10 ;git commit -am "My Message"; git tag $TAG; git push origin $TAG +TAG=0.0.15 ;git commit -am "Version Info"; git tag $TAG; git push origin $TAG ``` ## Contributing diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..ce7a4af --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,48 @@ +/* +Copyright © 2024 NAME HERE +*/ +package cmd + +import ( + "fmt" + "runtime" + "runtime/debug" + + "github.com/spf13/cobra" +) + +// GitCommit @see https://icinga.com/blog/2022/05/25/embedding-git-commit-information-in-go-binaries/ +var GitCommit = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value + } + } + } + return "" +}() +var versionCmd = &cobra.Command{ + Use: "version", + Short: "check version of command", + Long: `check version of command`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Code Version:", GitCommit) + fmt.Println("Go Version:", runtime.Version()) + fmt.Println("GOOS:", runtime.GOOS) + }, +} + +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") +}