|
1 | 1 | # 阿里云命令行工具 (Aliyun Command Line Interface) |
| 2 | +[](https://travis-ci.org/aliyun/aliyun-cli) |
2 | 3 |
|
3 | 4 | 阿里云命令行工具(Alibaba Cloud Command Line Interface)是开源项目,您可以从[Github](https://github.com/aliyun/aliyun-cli)上获取最新版本的CLI。 |
4 | 5 |
|
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)。 |
6 | 7 |
|
7 | 8 | ## 简介 |
8 | 9 |
|
|
21 | 22 |
|
22 | 23 | 阿里云CLI工具下载、解压后即可使用,支持Mac, Linux, Windows平台(x64版本)。 您可以将解压的`aliyun`可执行文件移至`/usr/local/bin`目录下,或添加到`$PATH`中。 |
23 | 24 |
|
24 | | - 下载链接如下 (0.80 Beta): |
| 25 | + 下载链接如下 (3.0.1): |
25 | 26 |
|
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) |
35 | 30 |
|
36 | 31 | - **编译源码** |
37 | 32 |
|
@@ -169,4 +164,67 @@ $ aliyun newproduct --version 2018-01-01 --endpoint newproduct.aliyuncs.com --pa |
169 | 164 | 在使用`--force`参数时,必须指定以下两个参数: |
170 | 165 |
|
171 | 166 | - `--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 | + |
0 commit comments