Skip to content

Commit 31b9930

Browse files
authored
chore: add version flag to root command (#4)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent 0bf79b7 commit 31b9930

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ builds:
2020
ldflags:
2121
- -w
2222
- -s
23+
- -X github.com/linuxsuren/md-exec/cli.version={{.Version}}
2324
dist: release
2425
archives:
2526
- name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}"

cli/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
"github.com/spf13/cobra"
1515
)
1616

17+
// should be inject during the build process
18+
var version string
19+
1720
func NewRootCommand() (cmd *cobra.Command) {
1821
opt := &option{}
1922
cmd = &cobra.Command{
@@ -22,6 +25,7 @@ func NewRootCommand() (cmd *cobra.Command) {
2225
Args: cobra.ExactArgs(1),
2326
RunE: opt.runE,
2427
}
28+
cmd.Version = version
2529
flags := cmd.Flags()
2630
flags.BoolVarP(&opt.loop, "loop", "", true, "Run the Markdown in loop mode.")
2731
return

0 commit comments

Comments
 (0)