Skip to content

Commit 987767f

Browse files
committed
conflict-fix
2 parents 73b02d5 + 5ea684d commit 987767f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2548
-1453
lines changed

.travis.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
language: go
22

3-
sudo: false
3+
sudo: true
44

55
go:
6-
- 1.7.x
76
- 1.8.x
8-
- 1.9.x
9-
- 1.10.x
7+
8+
branches:
9+
only:
10+
- master
11+
- pre-release
12+
13+
before_install:
14+
- sudo apt-get install -y jq
1015

1116
install:
1217
- make deps
1318
- make testdeps
1419

1520
notifications:
16-
#webhooks: https://oapi.dingtalk.com/robot/send?access_token=096ed387df243a6d60835aadeccc47165f3813bc7cb81cdd0cfeadfd28e3acc1
21+
webhooks: https://oapi.dingtalk.com/robot/send?access_token=096ed387df243a6d60835aadeccc47165f3813bc7cb81cdd0cfeadfd28e3acc1
1722
email: false
1823
on_success: change
1924
on_failure: always
2025

2126
script:
2227
- make build
23-
- go test -v -timeout 30m ./...
28+
- sudo cp out/aliyun /usr/local/bin
29+
- cd ./integration && ./test

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# CHANGE LOG
22

3+
### 3.0.1 Final Version
4+
5+
- support `version` command
6+
- fix `--dryrun` flag bugs
7+
-
8+
9+
### 3.0.0 GA Version
10+
11+
- refactoring cli package design, support composite flag with fields
12+
- refactoring openapi package design, make it more extensible
13+
- support `--quiet` flag
14+
- support `--dryrun` flag
15+
- support `aliyun oss --profile xxx`
16+
17+
### 0.81
18+
19+
- support `--output`
20+
- support `--waiter`
21+
- use `go -ldflags` to enable single Version in Makefile
22+
323
### 0.80
424

525
- support auto completion for zsh/bash

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export VERSION=0.80
1+
export VERSION=3.0.1
22

33
all: build
44
publish: build build_mac build_linux build_windows
@@ -15,14 +15,15 @@ deps:
1515
go get github.com/aliyun/alibaba-cloud-sdk-go/sdk
1616
go get github.com/posener/complete
1717
go get github.com/aliyun/ossutil/lib
18+
go get gopkg.in/yaml.v2
1819

19-
testdeps:
20+
testdeps: deps
2021
go get -v github.com/onsi/ginkgo/ginkgo
2122
go get -v github.com/onsi/gomega
2223
go install github.com/onsi/ginkgo/ginkgo
2324
go get gopkg.in/check.v1
2425

25-
metas:
26+
metas: deps
2627
go-bindata -o resource/metas.go -pkg resource -prefix ../aliyun-openapi-meta ../aliyun-openapi-meta/**/* ../aliyun-openapi-meta/products.json
2728

2829
clean:
@@ -38,16 +39,16 @@ install: build
3839
build_mac:
3940
GOOS=darwin GOARCH=amd64 go build -o out/aliyun main/main.go
4041
tar zcvf out/aliyun-cli-macosx-${VERSION}-amd64.tgz -C out aliyun
41-
aliyun oss cp out/aliyun-cli-macosx-${VERSION}-amd64.tgz oss://aliyun-cli --force
42+
aliyun oss cp out/aliyun-cli-macosx-${VERSION}-amd64.tgz oss://aliyun-cli --force --profile oss
4243

4344
build_linux:
4445
GOOS=linux GOARCH=amd64 go build -o out/aliyun main/main.go
4546
tar zcvf out/aliyun-cli-linux-${VERSION}-amd64.tgz -C out aliyun
46-
aliyun oss cp out/aliyun-cli-linux-${VERSION}-amd64.tgz oss://aliyun-cli --force
47+
aliyun oss cp out/aliyun-cli-linux-${VERSION}-amd64.tgz oss://aliyun-cli --force --profile oss
4748

4849
build_windows:
4950
GOOS=windows GOARCH=amd64 go build -o aliyun.exe main/main.go
5051
zip -r out/aliyun-cli-windows-${VERSION}-amd64.zip aliyun.exe
51-
aliyun oss cp out/aliyun-cli-windows-${VERSION}-amd64.zip oss://aliyun-cli --force
52+
aliyun oss cp out/aliyun-cli-windows-${VERSION}-amd64.zip oss://aliyun-cli --force --profile oss
5253
rm aliyun.exe
5354

README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Aliyun Command Line Interface
2+
[![Build Status](https://travis-ci.org/aliyun/aliyun-cli.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-cli)
23

34
[中文文档](./README_zh.md)
45

56
The Alibaba Cloud CLI is an open source tool, you can get the latest version from [GitHub](https://github.com/aliyun/aliyun-cli).
67

7-
This version is a new version built on Go. The new CLI is in the testing phase. If you want to use the old version (built on Alibaba Cloud Python SDK), click [here](https://github.com/aliyun/aliyun-cli/tree/python_final).
8+
This version is a new version built on Go. If you want to use the old version (built on Alibaba Cloud Python SDK), click [here](https://github.com/aliyun/aliyun-cli/tree/python_final).
89

910
## Introduction
1011

@@ -22,17 +23,11 @@ You can install Alibaba Cloud CLI either through the installer or the source cod
2223

2324
Download the installer, then extract the installer. You can move the extracted `aliyun` executable file to the `/usr/local/bin` directory or add it to the `$PATH`.
2425

25-
Download link: (0.80 Beta)
26+
Download link: (3.0.1)
2627

27-
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-0.70-amd64.tgz)
28-
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-0.70-amd64.tgz)
29-
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-0.70-amd64.zip)
30-
31-
Download link: (0.70 Beta)
32-
33-
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-0.60-amd64.tgz)
34-
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-0.60-amd64.tgz)
35-
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-0.60-amd64.zip)
28+
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-3.0.1-amd64.tgz)
29+
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-3.0.1-amd64.tgz)
30+
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-3.0.1-amd64.zip)
3631

3732
- **Compile source code**
3833

README_zh.md

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# 阿里云命令行工具 (Aliyun Command Line Interface)
2+
[![Build Status](https://travis-ci.org/aliyun/aliyun-cli.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-cli)
23

34
阿里云命令行工具(Alibaba Cloud Command Line Interface)是开源项目,您可以从[Github](https://github.com/aliyun/aliyun-cli)上获取最新版本的CLI。
45

5-
该版本的CLI为Go语言重构版本,目前处于**BETA**发布中,如果您想使用原有的Python版本,请切换到[Python分支](https://github.com/aliyun/aliyun-cli/tree/python_final)
6+
该版本的CLI为Go语言重构版本,如果您想使用原有的Python版本,请切换到[Python分支](https://github.com/aliyun/aliyun-cli/tree/python_final)
67

78
## 简介
89

@@ -21,17 +22,11 @@
2122

2223
阿里云CLI工具下载、解压后即可使用,支持Mac, Linux, Windows平台(x64版本)。 您可以将解压的`aliyun`可执行文件移至`/usr/local/bin`目录下,或添加到`$PATH`中。
2324

24-
下载链接如下 (0.80 Beta):
25+
下载链接如下 (3.0.1):
2526

26-
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-0.70-amd64.tgz)
27-
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-0.70-amd64.tgz)
28-
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-0.70-amd64.zip)
29-
30-
下载链接如下: (0.70 Beta)
31-
32-
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-0.60-amd64.tgz)
33-
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-0.60-amd64.tgz)
34-
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-0.60-amd64.zip)
27+
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-3.0.1-amd64.tgz)
28+
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-3.0.1-amd64.tgz)
29+
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-3.0.1-amd64.zip)
3530

3631
- **编译源码**
3732

@@ -169,4 +164,67 @@ $ aliyun newproduct --version 2018-01-01 --endpoint newproduct.aliyuncs.com --pa
169164
在使用`--force`参数时,必须指定以下两个参数:
170165

171166
- `--version`: 指定API的版本,你可以在API文档中找到版本号,如ECS的版本号是`2014-05-26`
172-
- `--endpoint`: 指定产品的接入地址,一般产品接入地址是`product.aliyuncs.com`,或`product.en-central-1.aliyuncs.com`,请参考各产品的API文档。
167+
- `--endpoint`: 指定产品的接入地址,一般产品接入地址是`product.aliyuncs.com`,或`product.en-central-1.aliyuncs.com`,请参考各产品的API文档。
168+
169+
#### 使用`--output`参数
170+
171+
阿里云产品的查询接口会返回json结构化数据,不方便阅读。例如:
172+
173+
```
174+
$ aliyun ecs DescribeInstances
175+
```
176+
177+
执行以上命令将得到以下json结果:
178+
179+
```
180+
{
181+
"PageNumber": 1,
182+
"TotalCount": 2,
183+
"PageSize": 10,
184+
"RequestId": "2B76ECBD-A296-407E-BE17-7E668A609DDA",
185+
"Instances": {
186+
"Instance": [
187+
{
188+
"ImageId": "ubuntu_16_0402_64_20G_alibase_20171227.vhd",
189+
"InstanceTypeFamily": "ecs.xn4",
190+
"VlanId": "",
191+
"InstanceId": "i-12345678912345678123",
192+
"Status": "Stopped",
193+
//omit some fields
194+
},
195+
Instance": [
196+
{
197+
"ImageId": "ubuntu_16_0402_64_20G_alibase_20171227.vhd",
198+
"InstanceTypeFamily": "ecs.xn4",
199+
"VlanId": "",
200+
"InstanceId": "i-abcdefghijklmnopqrst",
201+
"Status": "Running",
202+
//omit some fields
203+
},
204+
]
205+
}
206+
}
207+
```
208+
209+
可以使用`--output`参数提取结果中感兴趣的字段,并进行表格化输出。例如:
210+
211+
212+
```
213+
$ aliyun ecs DescribeInstances --output cols=InstanceId,Status
214+
```
215+
216+
执行以上命令将得到以下形式的结果:
217+
```
218+
InstanceId | Status
219+
---------- | ------
220+
i-12345678912345678123 | Stopped
221+
i-abcdefghijklmnopqrst | Running
222+
```
223+
224+
在使用`--output`参数时,必须指定以下参数:
225+
226+
- `--cols`: 表格的列名,需要与json数据中的字段相对应。如ECS DescribeInstances 接口返回结果中的字段`InstanceId` 以及 `Status`
227+
228+
可选参数:
229+
- `--rows`: 通过[jmespath](http://jmespath.org/)查询语句来指定表格行在json结果中的数据来源。当查询语句具有`Instances.Instance[]`的形式时,可以省略该参数。
230+

cli/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ Because aliyun cli need process unknown flags,and the following popular library
2525
### TODO
2626

2727
- [x] Suggestions
28-
- [ ] Support shorthand flag, -a -b
29-
- [ ] Flag alias
30-
- [ ] Auto complete framework
28+
- [x] Support shorthand flag, -a -b
29+
- [x] Flag alias
30+
- [x] Auto complete framework
3131
- [ ] Help document generation (ref: https://github.com/spf13/cobra#generating-documentation-for-your-command)
3232
- [ ] Optimize --help message view
33+
- [ ] Support `help --waiter`
34+
- [x] Support Group Options
35+
- [x] Optimize noticeable error
36+
- [ ] (low)Support shorthand combination -ab
37+
3338

cli/command.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *Command) ExecuteComplete(ctx *Context, args []string) {
121121
if f.Hidden {
122122
continue
123123
}
124-
if !strings.HasPrefix("--"+f.Name, ctx.completion.Current) {
124+
if !strings.HasPrefix("--" + f.Name, ctx.completion.Current) {
125125
continue
126126
}
127127
fmt.Printf("--%s\n", f.Name)
@@ -178,7 +178,7 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
178178
}
179179
}
180180

181-
//
181+
// cmd is find by args, try run cmd.Run
182182
// parse remain args
183183
remainArgs, err := parser.ReadAll()
184184
if err != nil {
@@ -192,7 +192,7 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
192192
return err
193193
}
194194

195-
if ctx.flags.IsAssigned("help", "") {
195+
if HelpFlag.IsAssigned() {
196196
ctx.help = true
197197
}
198198
callArgs := make([]string, 0)
@@ -231,36 +231,22 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
231231
}
232232

233233
func (c *Command) processError(err error) {
234-
//
235-
// process error
236-
//if e, ok := err.(PrintableError); ok {
237-
// Errorf("error: %s\n", e.GetText(i18n.GetLanguage()))
238-
//} else {
239234
Errorf("ERROR: %s\n", err.Error())
240-
// }
241-
242235
if e, ok := err.(SuggestibleError); ok {
243-
ss := e.GetSuggestions()
244-
if len(ss) > 0 {
245-
Noticef("\ndid you mean: \n %s \n", ss[0])
246-
}
236+
PrintSuggestions(i18n.GetLanguage(), e.GetSuggestions())
237+
return
238+
}
239+
if e, ok := err.(ErrorWithTip); ok {
240+
Noticef("\n%s\n", e.GetTip(i18n.GetLanguage()))
241+
return
247242
}
248243
}
249244

250245
func (c *Command) executeHelp(ctx *Context, args []string) {
251246
if c.Help != nil {
252247
err := c.Help(ctx, args)
253248
if err != nil {
254-
Errorf("Error: %s\n", err)
255-
}
256-
if se, ok := err.(SuggestibleError); ok {
257-
ss := se.GetSuggestions()
258-
if len(ss) > 0 {
259-
Noticef("\nDid you mean:\n")
260-
for _, s := range ss {
261-
Noticef(" %s\n", s)
262-
}
263-
}
249+
c.processError(err)
264250
}
265251
return
266252
}

cli/command_help.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (c *Command) PrintSubCommands() {
4343
}
4444

4545
func (c *Command) PrintFlags(ctx *Context) {
46-
if len(c.flags.Flags()) == 0 {
46+
if len(c.Flags().Flags()) == 0 {
4747
return
4848
}
4949

@@ -57,11 +57,11 @@ func (c *Command) PrintFlags(ctx *Context) {
5757
if flag.Hidden {
5858
continue
5959
}
60-
format := "--%s\t%s\n"
61-
if flag.Shorthand != "" {
62-
format = fmt.Sprintf("-%s, %s", flag.Shorthand, format)
60+
s := "--" + flag.Name
61+
if flag.Shorthand != 0 {
62+
s = s + ",-" + string(flag.Shorthand)
6363
}
64-
fmt.Fprintf(w, " "+format, flag.Name, flag.Usage.Text())
64+
fmt.Fprintf(w, " %s\t%s\n", s, flag.Short.Text())
6565
}
6666
w.Flush()
6767
}

cli/completion_installer.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
/*
2+
* Copyright (C) 2017-2018 Alibaba Group Holding Limited
3+
*/
14
package cli
25

36
import (
47
"fmt"
58
"github.com/aliyun/aliyun-cli/i18n"
69
)
710

11+
var uninstallFlag = &Flag{
12+
Name: "uninstall",
13+
Short: i18n.T("uninstall auto completion", "卸载自动完成"),
14+
}
15+
816
func NewAutoCompleteCommand() *Command {
917
cmd := &Command{
1018
Name: "auto-completion",
@@ -20,18 +28,15 @@ func NewAutoCompleteCommand() *Command {
2028
// // i = append(i, zshInstaller{f})
2129
// fmt.Printf("zshInstaller: %s\n", f)
2230
//}
23-
if ctx.flags.IsAssigned("uninstall", "") {
31+
if uninstallFlag.IsAssigned() {
2432
uninstallCompletion("aliyun")
2533
} else {
2634
installCompletion("aliyun")
2735
}
2836
return nil
2937
},
3038
}
31-
cmd.Flags().Add(Flag{
32-
Name: "uninstall",
33-
Usage: i18n.T("uninstall auto completion", "卸载自动完成"),
34-
})
39+
cmd.Flags().Add(uninstallFlag)
3540
return cmd
3641
}
3742

0 commit comments

Comments
 (0)