Skip to content

Commit

Permalink
chore(cmd): adds eotsd version command (#175)
Browse files Browse the repository at this point in the history
```
lazar@Lazars-MacBook-Pro finality-provider % ./build/eotsd v
Version:       0.12.0-9-g965510a
Git Commit:    965510a
Git Timestamp: 2024-11-28T12:51:34Z

```

[tracking
issue](#174)
  • Loading branch information
Lazar955 authored Nov 29, 2024
1 parent 965510a commit 5a267ce
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#175](https://github.com/babylonlabs-io/finality-provider/pull/175) adds: `eotsd version` command

### Bug Fixes

* [#166](https://github.com/babylonlabs-io/finality-provider/pull/166) fix: `eotsd keys add` `--output` flag
Expand Down
2 changes: 2 additions & 0 deletions eotsmanager/cmd/eotsd/daemon/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package daemon

import (
"github.com/babylonlabs-io/finality-provider/version"
"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
Expand All @@ -23,6 +24,7 @@ func NewRootCmd() *cobra.Command {
NewInitCmd(),
NewKeysCmd(),
NewStartCmd(),
version.CommandVersion("eotsd"),
)

return rootCmd
Expand Down
40 changes: 3 additions & 37 deletions finality-provider/cmd/fpd/daemon/daemon_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ package daemon

import (
"context"
"cosmossdk.io/math"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/babylonlabs-io/finality-provider/finality-provider/proto"
fpversion "github.com/babylonlabs-io/finality-provider/version"

"cosmossdk.io/math"
"github.com/babylonlabs-io/babylon/types"
"github.com/babylonlabs-io/finality-provider/finality-provider/proto"
"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"strconv"

fpcmd "github.com/babylonlabs-io/finality-provider/finality-provider/cmd"
fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
Expand Down Expand Up @@ -570,33 +566,3 @@ func loadKeyName(homeDir string, cmd *cobra.Command) (string, error) {
}
return keyName, nil
}

// CommandVersion prints cmd version
func CommandVersion() *cobra.Command {
var cmd = &cobra.Command{
Use: "version",
Short: "Prints version of this binary.",
Aliases: []string{"v"},
Example: `fpd version`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
version := fpversion.Version()
commit, ts := fpversion.CommitInfo()

if version == "" {
version = "main"
}

var sb strings.Builder
_, _ = sb.WriteString("Version: " + version)
_, _ = sb.WriteString("\n")
_, _ = sb.WriteString("Git Commit: " + commit)
_, _ = sb.WriteString("\n")
_, _ = sb.WriteString("Git Timestamp: " + ts)
_, _ = sb.WriteString("\n")

cmd.Printf(sb.String()) //nolint:govet // it's not an issue
},
}
return cmd
}
3 changes: 2 additions & 1 deletion finality-provider/cmd/fpd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/babylonlabs-io/finality-provider/version"
"os"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -34,7 +35,7 @@ func main() {
daemon.CommandGetDaemonInfo(), daemon.CommandCreateFP(), daemon.CommandLsFP(),
daemon.CommandInfoFP(), daemon.CommandRegisterFP(), daemon.CommandAddFinalitySig(),
daemon.CommandExportFP(), daemon.CommandTxs(), daemon.CommandUnjailFP(),
daemon.CommandEditFinalityDescription(), daemon.CommandVersion(),
daemon.CommandEditFinalityDescription(), version.CommandVersion("fpd"),
daemon.CommandCommitPubRand(),
)

Expand Down
37 changes: 37 additions & 0 deletions version/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package version

import (
"fmt"
"github.com/spf13/cobra"
"strings"
)

// CommandVersion prints cmd version
func CommandVersion(binaryName string) *cobra.Command {
var cmd = &cobra.Command{
Use: "version",
Short: "Prints version of this binary.",
Aliases: []string{"v"},
Example: fmt.Sprintf("%s version", binaryName),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
v := Version()
commit, ts := CommitInfo()

if v == "" {
v = "main"
}

var sb strings.Builder
_, _ = sb.WriteString("Version: " + v)
_, _ = sb.WriteString("\n")
_, _ = sb.WriteString("Git Commit: " + commit)
_, _ = sb.WriteString("\n")
_, _ = sb.WriteString("Git Timestamp: " + ts)
_, _ = sb.WriteString("\n")

cmd.Printf(sb.String()) //nolint:govet // it's not an issue
},
}
return cmd
}

0 comments on commit 5a267ce

Please sign in to comment.