Skip to content

Commit

Permalink
added version command
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekz committed Aug 27, 2023
1 parent b1d1885 commit 3ff2374
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
VERSION = $$(git describe --abbrev=0 --tags)
COMMIT_REV = $$(git rev-list -n 1 $(VERSION))

version:
@echo $(VERSION)

commit_rev:
@echo $(COMMIT_REV)

build:
go build -o bin/tui
go build -ldflags "-X github.com/tomekz/coincap-tui/cmd.version=$(VERSION)" -o bin/tui

run: build
./bin/tui
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ coincap-tui let's you check crypto prices in your terminal.

Features:
- fetch crypto assets data from [ coincap ](https://docs.coincap.io/) REST API
- save favourites
- Favourties: save and view favourite coins
- display results in tabular format
- nice UI with [bubble-tea](https://github.com/charmbracelet/bubbletea)

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Features:
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
rootCmd.AddCommand(VersionCmd())
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
41 changes: 41 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"fmt"
"runtime/debug"
"strings"

"github.com/spf13/cobra"
)

var version string

// Version returns coincap-tui version
func Version() string {
ver := "(devel)"
if version != "" {
ver = version
} else if buildInfo, ok := debug.ReadBuildInfo(); ok {
ver = buildInfo.Main.Version
}

if !strings.HasPrefix(ver, "v") {
ver = fmt.Sprintf("v%s", ver)
}

return ver
}

// VersionCmd ...
func VersionCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Displays the current version",
Long: `The version command displays the current version`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(Version())
},
}

return versionCmd
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/tomekz/coincap-tui/cmd"
)

var version string

func main() {
cmd.Execute()
}

0 comments on commit 3ff2374

Please sign in to comment.