Skip to content

Commit a1df65f

Browse files
appleapple
authored andcommitted
bbx: 增加version命令,显示bbx工具的版本信息。变更makefile文件,增加帮助信息的输出
1 parent 0ae8c9b commit a1df65f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ else
99
endif
1010
endif
1111

12-
TAG := "v1.0.1"
12+
VERSION_FILE := cmd/version.go
13+
TAG := $(shell sed -rn 's/const version = "(.*)"/\1/p' $(VERSION_FILE))
1314
OS_LIST := windows darwin linux
1415
ARCH_LIST := 386 amd64 arm64
1516

1617
auto: $(TARGET)
1718

19+
test:
20+
@echo $(TAG)
21+
1822
tidy:
1923
@go mod tidy
2024

@@ -73,4 +77,4 @@ help:
7377
@echo "clean: make clean clean bbx and bbx.exe file"
7478
@echo "clean_all make clean_all clean all binary files"
7579
@echo "install: make install install binary file to GOBIN dir"
76-
@echo "gen_releases: make gen_releases [TAG=v1.0.1] generate releases into releases/\$$TAG dir"
80+
@echo "gen_releases: make gen_releases generate releases into releases/$(TAG)"

cmd/version.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
const version = "v1.0.2"
10+
11+
// versionCmd represents the version command
12+
var versionCmd = &cobra.Command{
13+
Use: "version",
14+
Short: "A brief description of your command",
15+
Long: `A longer description that spans multiple lines and likely contains examples
16+
and usage of using your command. For example:
17+
18+
Cobra is a CLI library for Go that empowers applications.
19+
This application is a tool to generate the needed files
20+
to quickly create a Cobra application.`,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
fmt.Println(version)
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(versionCmd)
28+
29+
// Here you will define your flags and configuration settings.
30+
31+
// Cobra supports Persistent Flags which will work for this command
32+
// and all subcommands, e.g.:
33+
// versionCmd.PersistentFlags().String("foo", "", "A help for foo")
34+
35+
// Cobra supports local flags which will only run when this command
36+
// is called directly, e.g.:
37+
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
38+
}

0 commit comments

Comments
 (0)