Skip to content

Commit 27d7ee3

Browse files
author
jxyowen
committed
build ldflags version
1 parent 95f8660 commit 27d7ee3

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ clean:
3030
rm -rf out/*
3131

3232
build: metas
33-
go build -o out/aliyun main/main.go
33+
go build -ldflags "-X 'github.com/aliyun/aliyun-cli/cli.Version=${VERSION}'" -o out/aliyun main/main.go
3434

3535
install: build
3636
cp out/aliyun /usr/local/bin

cli/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package cli
2+
3+
var (
4+
Version = "0.0.1"
5+
)

main/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ $ aliyuncli configure
3232
3333
$ aliyuncli Ecs DescribeInstances --secure
3434
*/
35-
const Version = "0.80 BETA"
3635

3736
var library = meta.LoadLibrary(resource.NewReader())
3837
var helper = openapi.NewHelper(library)
@@ -50,7 +49,7 @@ func main() {
5049

5150
rootCmd := &cli.Command{
5251
Name: "aliyun",
53-
Short: i18n.T("Alibaba Cloud Command Line Interface Version "+Version, "阿里云CLI命令行工具 "+Version),
52+
Short: i18n.T("Alibaba Cloud Command Line Interface Version "+cli.Version, "阿里云CLI命令行工具 "+cli.Version),
5453
Usage: "aliyun <product> <operation> [--parameter1 value1 --parameter2 value2 ...]",
5554
Sample: "aliyun ecs DescribeRegions",
5655
EnableUnknownFlag: true,

openapi/caller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (c *Caller) InitClient(ctx *cli.Context, product *meta.Product, isRpc bool)
130130
}
131131

132132
request := requests.NewCommonRequest()
133-
request.Headers["User-Agent"] = "Aliyun-CLI-V0.80"
133+
request.Headers["User-Agent"] = fmt.Sprintf("Aliyun-CLI-V%s", strings.Replace(cli.Version, " ", "-", -1))
134134
request.RegionId = c.profile.RegionId
135135
request.Product = product.Code
136136
request.Version = product.Version

oss/lib/cli_bridge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func NewCommandBridge(a Commander) *cli.Command {
6161

6262
if result.Flags().Get(name, "") == nil {
6363
result.Flags().Add(cli.Flag{
64-
Name: name,
64+
Name: name,
6565
Shorthand: shorthand,
66-
Usage: i18n.T(opt.helpEnglish, opt.helpChinese),
66+
Usage: i18n.T(opt.helpEnglish, opt.helpChinese),
6767
// Assignable: opt.optionType todo
6868
})
6969
}

0 commit comments

Comments
 (0)