Updated on 2023-02-27 GMT+08:00

Specifying Output Format

Use the --cli-query option in a command to pass a JMESPath expression so that you can extract key information from the return result. Use --cli-output to specify the output format of the response data and use --cli-output-num to specify whether to print the row numbers during table output.

Output Order

The sequence of parameters in the output result varies according to the JMESPath expression specified by --cli-query. The output result queried by some expressions does not contain the attribute names (parameter keys) of the output data. If you use these expressions, understand the sequence of the output data to facilitate data processing. The following table describes the output sequence of different types of JMESPath expressions.

Table 1 Data output sequence of different JMESPath expressions

JMESPath Expression Type

Example JMESPath Expression

Attribute Names Contained in JSON or Table Output

Attribute Names Contained in TSV Output

Data Output Sequence

Example Output

Object-level expression

--cli-query="items[0]"

Yes

No

In alphabetical order of the attribute names of the object

Example 1

Attribute-level expression without changing the attribute names

--cli-query="items[0].items[0].[spec.flavor,metadata.uid]"

No

No

In the attribute name order specified in the JMESPath expression

Example 2

Attribute-level expression with the attribute names changed

--cli-query="items[0].{Flavor:spec.flavor,ClusterID:metadata.uid}"

Yes

No

In alphabetical order of the new attribute names

Example 3

The following examples show the sequence of data output in JSON format through different JMESPath expressions:

  • Example 1
    When an object is specified, KooCLI outputs the attribute values in alphabetical order of the attribute names of the object. In this example, the object items[0] is specified. The attributes of the object are sorted in alphabetical order as follows: apiVersion, kind, metadata, spec, status. The output result is as follows:
    hcloud CCE ListClusters --cli-region="eu-west-101" --type="VirtualMachine" --project_id="0dd8cb****************19b5a84546" --cli-query="items[0]"
    {
      "apiVersion": "v3",
      "kind": "Cluster",
      "metadata": {
        "creationTimestamp": "2022-05-13 08:51:58.252509 +0000 UTC",
        "labels": {
          "FeatureGates": "elbv3,"
        },
        "name": "github-*****-****",
        "uid": "f288****-****-****-****-****ac101534",
        "updateTimestamp": "2022-05-13 09:10:06.395875 +0000 UTC"
      },
      "spec": {
        "authentication": {
          "authenticatingProxy": {},
          "mode": "rbac"
        },
        "az": "multi_az",
        "billingMode": 0,
        "category": "CCE",
        "containerNetwork": {
          "cidr": "10.*.*.*/**",
          "mode": "vpc-router"
        },
        "eniNetwork": {},
        "extendParam": {
          "alpha.cce/fixPoolMask": "25",
          "kubernetes.io/cpuManagerPolicy": "",
          "upgradefrom": ""
        },
        "flavor": "cce.s2.small",
        "hostNetwork": {
          "SecurityGroup": "653e****-****-****-****-****6a23eb7e",
          "subnet": "d5df****-****-****-****-****4955c724",
          "vpc": "c865****-****-****-****-****efe7e8d8"
        },
        "kubeProxyMode": "iptables",
        "kubernetesSvcIpRange": "10.***.*.*/**",
        "masters": [
          {
            "availabilityZone": ""
          }
        ],
        "supportIstio": true,
        "type": "VirtualMachine",
        "version": "v1.19.10-r0"
      },
      "status": {
        "endpoints": [
          {
            "type": "Internal",
            "url": "https://192.***.*.***:5443"
          },
          {
            "type": "External",
            "url": "https://121.**.**.***:5443"
          }
        ],
        "phase": "Available"
      }
    }
  • Example 2

    When specific attributes of an object are specified without changing the attribute names, KooCLI outputs the attribute values in the order that the attribute names are specified. In this example, the expression items[0].[spec.flavor,metadata.uid] specifies the child attribute flavor of spec and uid of metadata under the object items[0]. In the output result, the value of spec.flavor is displayed prior to that of metadata.uid.

    hcloud CCE ListClusters --cli-region="eu-west-101" --type="VirtualMachine" --project_id="0dd8cb****************19b5a84546" --cli-query="items[0].[spec.flavor,metadata.uid]"
    [
      "cce.s2.small",
      "f288****-****-****-****-****ac101534"
    ]
  • Example 3

    When specific attributes of an object are specified with the attribute names changed, KooCLI outputs the attribute values in alphabetical order of the new attribute names. In this example, the child attributes of two attributes under the object items[0] are specified. The expression items[0].{Flavor:spec.flavor,ClusterID:metadata.uid} renames the flavor attribute of spec Flavor and renames the uid attribute of metadata ClusterID. The new attributes are sorted in alphabetical order as follows: ClusterID, Flavor. Therefore, the output result is as follows:

    hcloud CCE ListClusters --cli-region="eu-west-101" --type="VirtualMachine" --project_id="0dd8cb****************19b5a84546" --cli-query="items[0].{Flavor:spec.flavor,ClusterID:metadata.uid}"
    {
      "ClusterID": "f288****-****-****-****-****ac101534",
      "Flavor": "cce.s2.small"
    }

Output Format

Use --cli-output to specify the output format. The value can be json, table, or tsv.

  • When the value of --cli-output is json:
    The result is output in JSON format as follows:
    hcloud configure list --cli-output=json --cli-query="profiles[].{Name:name,Mode:mode,Ak:accessKeyId,SK:secretAccessKey}"
    [
      {
        "Ak": "8NV****IOV",
        "Mode": "AKSK",
        "Name": "test",
        "SK": "****"
      },
      {
        "Ak": "H9N****MXW",
        "Mode": "AKSK",
        "Name": "default",
        "SK": "****"
      }
    ]
  • When the value of --cli-output is table:

    The result is output in a table as follows:

    In the meantime, you can use --cli-output-num to specify whether to print the row numbers.

  • When the value of --cli-output is tsv:

    The result is output in TSV format as follows:

    In TSV format output, data values are separated by tab characters and line breaks, and no extra symbols are included. You can use the output result for other commands. The TSV output result does not contain table headers. To prevent confusion when using the data for other commands, you need to understand the data output sequence of different types of JMESPath expressions. For details, see Output Order.

    If multiple attributes are specified but not renamed in a JMESPath expression for TSV format output, attributes enclosed in square brackets ([]) will be displayed in new lines. The following is an example:

    In this example, the attributes name, mode, accessKeyId, and secretAccessKey are specified. Attribute name is output in a new line. The attributes are output in the order that they appear in the command. The first line displays the values of mode, accessKeyId, and secretAccessKey, and the second line displays the value of name.

For details about other precautions for using --cli-query, --cli-output, and --cli-output-num, see FAQs.