Skip to content

Commit

Permalink
local-ic version
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jun 22, 2024
1 parent f326371 commit 5dd2b96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion local-interchain/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/make -f

CWD := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
COMMIT := $(shell git log -1 --format='%H')

ldflags = -X main.MakeFileInstallDirectory=$(CWD)
# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags --always)
ifeq (,$(VERSION))
VERSION := $(COMMIT)
endif
endif

ldflags = -X main.MakeFileInstallDirectory=$(CWD) -X main.Version=$(VERSION)
ldflags := $(strip $(ldflags))
BUILD_FLAGS := -ldflags '$(ldflags)'

Expand Down
13 changes: 13 additions & 0 deletions local-interchain/cmd/local-ic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ package main
import (
"fmt"
"os"

"github.com/spf13/cobra"
)

// set in the Makefile
var Version = ""

func main() {
rootCmd.AddCommand(chainsCmd)
rootCmd.AddCommand(newChainCmd)
rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(interactCmd)
rootCmd.AddCommand(&cobra.Command{
Use: "version",
Aliases: []string{"ver"},
Short: "Print the version of Local-IC",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(Version)
},
})

if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "error while executing your CLI. Err: %v\n", err)
Expand Down

0 comments on commit 5dd2b96

Please sign in to comment.