Skip to content

Commit 5ea684d

Browse files
committed
README_zh.md add --output example
1 parent 414abd8 commit 5ea684d

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
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).
99

1010
## Introduction
1111

README_zh.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
该版本的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)
77

88
## 简介
99

@@ -166,4 +166,65 @@ $ aliyun newproduct --version 2018-01-01 --endpoint newproduct.aliyuncs.com --pa
166166
- `--version`: 指定API的版本,你可以在API文档中找到版本号,如ECS的版本号是`2014-05-26`
167167
- `--endpoint`: 指定产品的接入地址,一般产品接入地址是`product.aliyuncs.com`,或`product.en-central-1.aliyuncs.com`,请参考各产品的API文档。
168168

169-
- `--waiter timeout=xxx`
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+

0 commit comments

Comments
 (0)