Skip to content

Commit

Permalink
chore: add version subcommand (#32)
Browse files Browse the repository at this point in the history
chore: add to rootcmd
  • Loading branch information
artemijspavlovs authored Jul 9, 2024
1 parent 6302c03 commit 3a579d6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
export GO111MODULE = on

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H' | cut -c 1-8)

# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

ldflags = -X github.com/dymensionxyz/eibc-client/version.BuildVersion=$(VERSION)

BUILD_FLAGS := -ldflags '$(ldflags)'

###########
# Install #
###########
Expand All @@ -12,11 +28,11 @@ install: build
mv build/eibc $(GOPATH)/bin/eibc-client

.PHONY: build
build: go.sum ## Compiles the rollapd binary
build: go.sum ## Compiles the eibc binary
@echo "--> Ensure dependencies have not been modified"
@go mod verify
@echo "--> building eibc-client"
@go build -o build/eibc-client ./
@go build -o build/eibc-client $(BUILD_FLAGS) ./

###########
# Docker #
Expand Down
3 changes: 3 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/dymensionxyz/eibc-client/cmd/version"
"github.com/dymensionxyz/eibc-client/store"
utils "github.com/dymensionxyz/eibc-client/utils/viper"
)
Expand Down Expand Up @@ -325,6 +326,8 @@ func init() {
balancesCmd.Flags().BoolP("all", "a", false, "Filter by fulfillment status")
rootCmd.AddCommand(balancesCmd)

rootCmd.AddCommand(version.Cmd())

cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
Expand Down
20 changes: 20 additions & 0 deletions cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package version

import (
"fmt"

"github.com/spf13/cobra"

"github.com/dymensionxyz/eibc-client/version"
)

func Cmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version of roller",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version.BuildVersion)
},
}
return versionCmd
}
3 changes: 3 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var BuildVersion string

0 comments on commit 3a579d6

Please sign in to comment.