# 命令结构

本指南将介绍 Zenlayer Cloud CLI 命令的基本结构和语法。

## 命令结构概述

Zenlayer Cloud CLI 使用多层结构的命令格式，基本结构如下：

```bash
zeno [全局选项] <命令> [子命令] [参数]
```

### 各部分说明

* **全局选项**：适用于所有命令的选项，如 `--profile`、`--output` 等
* **命令**：对应于 Zenlayer Cloud 服务，如 `zec`（弹性算力）等
* **子命令**：对应于服务的具体操作，如 `describe-instances`、`create-zec-instances` 等
* **参数**：命令的具体参数，如 `--instance-id`、`--instance-type` 等

## 命令示例

### 示例 1：列出所有云服务器实例

```bash
zeno zec describe-instances
```

### 示例 2：使用特定配置文件列出云服务器实例

```bash
zeno --profile prod zec describe-instances
```

### 示例 3：创建云服务器实例

```bash
zeno zec create-zec-instances --instance-type z2a.1c2g --count 1 --region-id asia-east-1
```

### 示例 4：使用 JSON 输出格式

```bash
zeno zec describe-instances --output json
```

## 命令层次结构

Zenlayer Cloud CLI 的命令层次结构如下：

1. **根命令**：`zeno`
2. **服务命令**：如 `zec` 等
3. **操作命令**：如 `describe-instances`、`create-zec-instances` 等

### 命令层次示例

```
zeno
├── configure
├── version
└── zec
    ├── create-zec-instances
    ├── describe-instances
    ├── release-instances
    ├── modify-instances-attribute
    └── start-instances
```

## 全局选项

Zenlayer Cloud CLI 支持以下全局选项：

| 选项                    | 缩写          | 描述                   |
| --------------------- | ----------- | -------------------- |
| `--profile`           | `-p`        | 指定要使用的配置文件           |
| `--output`            | `-o`        | 指定输出格式（json 或 table） |
| `--query`             | `-q`        | 使用 JMESPath 查询过滤输出   |
| `--access-key-id`     | <p><br></p> | 指定访问密钥 ID            |
| `--access-key-secret` | <p><br></p> | 指定访问密钥密钥             |
| `--debug`             | <p><br></p> | 启用调试模式               |
| `--help`              | `-h`        | 显示帮助信息               |

## 命令命名规范

Zenlayer Cloud CLI 的命令命名遵循以下规范：

* **服务命令**：使用服务的缩写，如 `zec`（弹性算力）等
* **操作命令**：使用动词+名词的形式，如 `describe-instances`、`create-zec-instances` 等
* **参数**：使用小写字母和连字符，如 `--instance-id`、`--instance-type` 等

## 命令执行流程

当您执行一个 Zenlayer Cloud CLI 命令时，发生以下流程：

1. CLI 解析命令和参数
2. 加载配置（从配置文件或环境变量）
3. 验证凭证
4. 构建 API 请求
5. 发送请求到 Zenlayer Cloud API
6. 处理响应
7. 以指定的格式输出结果

## 命令最佳实践

* **使用帮助**：使用 `--help` 选项获取命令的详细信息
* **使用自动补全**：设置命令自动补全，提高输入效率
* **使用配置文件**：为不同环境创建配置文件，方便切换
* **使用输出格式**：根据需要选择合适的输出格式
* **使用查询过滤**：使用 `--query` 选项过滤输出，只获取需要的信息

## 常见问题

### 命令未找到

如果运行命令时出现 "command not found" 错误，请检查：

* CLI 是否正确安装
* 命令是否拼写正确
* 服务是否支持该命令

### 参数错误

如果出现参数错误，请检查：

* 参数名称是否正确
* 参数值是否符合要求
* 是否缺少必要的参数


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/zenlayer-cli/cn/usage/command-structure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
