Advanced
Тема интерфейса

How Do I Use cli-output-rows, cli-output-cols, and cli-output-num?

By default, results are returned in JSON format when you call cloud service APIs using Cloud CLI. Cloud CLI supports the --cli-output-rows, --cli-output-cols, and --cli-output-num parameters to output data in table format. These parameters facilitate the extraction of key information in the calling result.

By default, the original calling result is output in JSON format:

cloud ECS NovaListServers --cli-region="ru-moscow-1" --project_id="0dd8cb****************19b5a84546"
{
"servers": [
{
"name": "ecs-a6b4",
"links": [
{
"rel": "self",
"href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/v2.1/0dd8cb****************19b5a84546/servers/4f06****-****-****-****-****04dd856a"
},
{
"rel": "bookmark",
"href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/0dd8cb****************19b5a84546/servers/4f06****-****-****-****-****04dd856a"
}
],
"id": "4f06****-****-****-****-****04dd856a"
},
{
"name": "hdn-docker",
"links": [
{
"rel": "self",
"href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/v2.1/0dd8cb****************19b5a84546/servers/6731****-****-****-****-****0bc463f0"
},
{
"rel": "bookmark",
"href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/0dd8cb****************19b5a84546/servers/6731****-****-****-****-****0bc463f0"
}
],
"id": "6731****-****-****-****-****0bc463f0"
},
{
"name": "ecs-8f88",
"links": [
{
"rel": "self",
"href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/v2.1/0dd8cb****************19b5a84546/servers/06a2****-****-****-****-****c79a1a26"
},
{
"rel": "bookmark",
"href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/0dd8cb****************19b5a84546/servers/06a2****-****-****-****-****c79a1a26"
}
],
"id": "06a2****-****-****-****-****c79a1a26"
}
]
}

During table output, --cli-output-rows specifies a JSON structure level, that is, the data source of the table, --cli-output-cols specifies the column names of the table, which must correspond to the fields in the JSON structure, and --cli-output-num specifies whether to print the row numbers of the table (the default value is true).

cloud ECS NovaListServers --cli-region="ru-moscow-1" --project_id="0dd8cb******************b5a84546" --cli-output-rows="servers" --cli-output-cols="name,id"

The --cli-output-rows, --cli-output-cols, and --cli-output-num parameters can also be used in system commands. For example:

cloud configure list --cli-output-rows="profiles[]"

cloud configure list --cli-output-rows="profiles[0]" --cli-output-cols="name,accessKeyId,secretAccessKey,projectId,region"

For details about how to use --cli-output-rows, --cli-output-cols, and --cli-output-num, see What Are the Precautions for Using cli-output-rows, cli-output-cols, and cli-output-num?