> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 查找并运行命令

> 找到完成某项任务的 difyctl 命令，用标志或 JSON 传值，再按结果中的建议运行后续步骤

> 本文档由 AI 自动翻译。如有任何不准确之处，请参考 [英文原版](/en/cli/find-and-run-commands.md)。

## 查找命令

在 `help` 后面用几个词描述要做的事，它会列出匹配的命令。例如，查找发布应用的命令：

```bash theme={null}
difyctl help publish app
```

如果想直接浏览，就单独运行 `difyctl help`：它会列出命令开头的那些词，如 `get`、`run`。再加上其中一个词，就能列出以它开头的全部命令：

```bash theme={null}
difyctl help get
```

找到命令后，用 `help` 加命令全名，即可查看它接受的字段（也就是要传给它的值）：

```bash theme={null}
difyctl help describe console_app
```

也可直接在命令后加上 `--help` 或 `-h`。

## 运行命令

> [!WARNING]
>
> `difyctl` 从不要求你确认命令，帮助中标为 `destructive` 的命令（如 `delete` 命令）也不例外。
>
> 运行破坏性命令前，先核对它要操作的 ID，例如用对应的 `get` 命令查看。

### 用标志传值

每个要用的字段都以对应的标志传入，后面跟上值。命令的帮助会列出它的标志，以及每个标志的类型、默认值和是否必填。例如，以下是 `run console_app workflow` 的部分帮助内容：

```text theme={null}
Flags
  --app-id       string             required
  --inputs       map<string, json>  optional  Variables declared by the app. …
  --workflow-id  string             optional  Pin a published workflow version
```

值该怎么传，由类型决定。大多数字段直接传值即可。例如，按 ID 查看某个应用，ID 可从 `difyctl get console_app` 列出的结果中找到：

```bash theme={null}
difyctl describe console_app --app-id 0a1b2c3d-4e5f-6789-abcd-ef0123456789
```

有三类字段的传法不同：

* `boolean` 字段只写标志即设为 true，加上 `=false` 则设为 false，例如 `run console_app chat` 的 `--auto-generate-name=false`。

* 列表字段（如 `string[]`）有几个值，就把标志重复写几次，例如 `install plugin` 的 `--identifiers a --identifiers b`。

* 类型为 `json`、`object` 或某种 `map` 的字段，以 JSON 文本作为标志的值。例如，使用上面帮助中的 `--inputs`：

  ```bash theme={null}
  difyctl run console_app workflow --app-id 0a1b2c3d-4e5f-6789-abcd-ef0123456789 --inputs '{"topic": "AI"}'
  ```

要改为从文件读取 JSON，写上 `@` 和文件路径，例如 `--inputs @inputs.json`。要从 stdin 读取，则写 `--inputs @-`。

`string` 字段中的 `@` 要格外留意：它从不读取文件。`--yaml-content @app.yml` 发送的是文本 `@app.yml` 本身，而非文件内容。要发送文件内容，可写成 `--yaml-content "$(cat app.yml)"`，让 Shell 去读取文件。

### 以 JSON 发送整个请求

如果请求由脚本生成，或者存放在文件里，就把所有字段放进一个 JSON 对象，用 `--input` 传入（末尾没有 s，不是上文的 `--inputs` 字段）。

每个字段都用字段名来写，即去掉标志开头的 `--`，再把连字符换成下划线（写 `app_id`，不写 `--app-id`）：

```bash theme={null}
difyctl run console_app workflow --input '{"app_id": "0a1b2c3d-4e5f-6789-abcd-ef0123456789", "inputs": {"topic": "AI"}}'
```

`--input` 也能从文件读取（如 `--input @request.json`），或从 stdin 读取（`--input @-`）。

标志的优先级高于 `--input` 中的同名字段。这样一来，可把请求存在文件里，每次运行只改一个值。如果 `request.json` 的内容是 `{"mode": "workflow", "limit": 50, "page": 1}`，下面的命令会列出 Workflow 应用的第 2 页：

```bash theme={null}
difyctl get console_app --input @request.json --page 2
```

## 按提示运行后续命令

有些结果带有 `hints`：服务器建议你接下来运行的命令，凡是服务器知道的值都已填好。如果某条提示正是你下一步要做的，直接运行它，不必自己拼装命令。

例如，用 `difyctl run console_app chat` 向聊天应用发送消息并收到回复后，结果中会带有这样一条提示：

```json theme={null}
{
  "hints": [
    {
      "summary": "Reply in this conversation",
      "op": "run.console_app.chat",
      "input": {
        "app_id": "0a1b2c3d-4e5f-6789-abcd-ef0123456789",
        "conversation_id": "9f8e7d6c-5b4a-4321-8fed-cba987654321",
        "query": null,
        "inputs": {}
      }
    }
  ],
  …
}
```

运行提示时，把 `op` 中的点换成空格写成命令，再把 `input` 传给 `--input`。其中每个 `null` 都要换成你自己的值。以这条提示为例，就是运行 `difyctl run console_app chat`，并把下一条消息填进 `query`：

```bash theme={null}
difyctl run console_app chat --input '{"app_id": "0a1b2c3d-4e5f-6789-abcd-ef0123456789", "conversation_id": "9f8e7d6c-5b4a-4321-8fed-cba987654321", "query": "那周末呢？", "inputs": {}}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.