Skip to content

Commit

Permalink
Version Info
Browse files Browse the repository at this point in the history
  • Loading branch information
schmiddim committed Jun 17, 2024
1 parent 69e4b31 commit 47c279c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
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")
}

0 comments on commit 47c279c

Please sign in to comment.