Skip to content

Commit 11064cd

Browse files
committed
Improve: add commit id in version information.
Signed-off-by: Wine93 <[email protected]>
1 parent b86b5a6 commit 11064cd

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ OUTPUT := bin/curveadm
2424
# build flags
2525
LDFLAGS := -s -w
2626
LDFLAGS += -extldflags "-static -fpic"
27+
LDFLAGS += -X github.com/opencurve/curveadm/cli/cli.CommitId=$(shell git rev-parse --short HEAD)
2728

2829
BUILD_FLAGS := -a
2930
BUILD_FLAGS += -trimpath

cli/cli/version.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ package cli
2626

2727
var (
2828
Version = "0.2.1"
29+
30+
CommitId = "unknown"
2931
)

cli/command/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func addSubCommands(cmd *cobra.Command, curveadm *cli.CurveAdm) {
9393
}
9494

9595
func setupRootCommand(cmd *cobra.Command, curveadm *cli.CurveAdm) {
96-
cmd.SetVersionTemplate("CurveAdm v{{.Version}}\n")
96+
cmd.SetVersionTemplate("{{.Version}}\n")
9797
cliutil.SetFlagErrorFunc(cmd)
9898
cliutil.SetHelpTemplate(cmd)
9999
cliutil.SetUsageTemplate(cmd)
@@ -106,7 +106,7 @@ func NewCurveAdmCommand(curveadm *cli.CurveAdm) *cobra.Command {
106106
cmd := &cobra.Command{
107107
Use: "curveadm [OPTIONS] COMMAND [ARGS...]",
108108
Short: "Deploy and manage CurveBS/CurveFS cluster",
109-
Version: cli.Version,
109+
Version: fmt.Sprintf("CurveAdm v%s, build %s", cli.Version, cli.CommitId),
110110
Example: curveadmExample,
111111
RunE: func(cmd *cobra.Command, args []string) error {
112112
if options.debug {

0 commit comments

Comments
 (0)