Skip to content

Commit

Permalink
add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Jan 9, 2024
1 parent bd7b450 commit 57016b0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 5 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
DIRTY := $(shell git status --porcelain | wc -l | xargs)

ldflags = -X github.com/strangelove-ventures/noble-cctp-relayer/cmd.Version=$(VERSION) \
-X github.com/strangelove-ventures/noble-cctp-relayer/cmd.Commit=$(COMMIT) \
-X github.com/strangelove-ventures/noble-cctp-relayer/cmd.Dirty=$(DIRTY)

ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

.PHONY: all format lint
all: format lint

Expand All @@ -17,3 +28,13 @@ lint:
@echo "🤖 Running linter..."
@go run $(golangci_lint_cmd) run --timeout=10m
@echo "✅ Completed linting!"


###############################################################################
### Install ###
###############################################################################

install: go.sum
@echo "🤖 Building noble-cctp-relayer..."
@go build -mod=readonly -ldflags '$(ldflags)' -o $(GOBIN)/noble-cctp-relayer main.go

18 changes: 18 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const (
flagJSON = "json"
)

func jsonFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagJSON, "j", false, "returns the response in json format")
if err := v.BindPFlag(flagJSON, cmd.Flags().Lookup(flagJSON)); err != nil {
panic(err)
}
return cmd
}
13 changes: 8 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/gin-gonic/gin"
"github.com/strangelove-ventures/noble-cctp-relayer/cmd/ethereum"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
"io"
"net/http"
"os"
"strconv"

"cosmossdk.io/log"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -46,7 +47,9 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "config.yaml", "")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "")

rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(
startCmd,
versionCmd)

cobra.OnInitialize(func() {
if verbose {
Expand Down
51 changes: 51 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cmd

import (
"fmt"
"runtime"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

var (
// Version defines the application version (defined at compile time)
Version = ""
Commit = ""
Dirty = ""
)

type versionInfo struct {
Version string `json:"version" yaml:"version"`
Commit string `json:"commit" yaml:"commit"`
Go string `json:"go" yaml:"go"`
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the relayer version info",
RunE: getVersionCmd,
}

func getVersionCmd(cmd *cobra.Command, args []string) error {
// jsn, err := cmd.Flags().GetBool(flagJSON)
// if err != nil {
// return err
// }

commit := Commit
if Dirty != "0" {
commit += " (dirty)"
}

verInfo := versionInfo{
Version: Version,
Commit: commit,
Go: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
}

bz, err := yaml.Marshal(&verInfo)

fmt.Fprintln(cmd.OutOrStdout(), string(bz))
return err
}

0 comments on commit 57016b0

Please sign in to comment.