-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cmd): adds eotsd version command (#175)
``` 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
Showing
5 changed files
with
48 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |