# @cloud-copilot/cli 中文文档

规范地址：https://npmcn.com/package/%40cloud-copilot/cli/

版本：0\.2\.66
npm 元数据更新时间：2026-08-29T12:04:58.345Z
中文译文更新时间：2026-11-10T02:19:52.374Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40cloud-copilot/cli
原文对照：https://npmcn.com/package/%40cloud-copilot/cli/?lang=original
项目主页：https://github.com/cloud-copilot/cli#readme
源码仓库：https://github.com/cloud-copilot/cli

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：204 kB，117 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2025-01-23T18:04:34.700Z
- 最新版本发布：2026-08-29T12:04:58.016Z
- 近 30 天下载量：4857（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：106（近 12 个月 48 个）

## 中文简介

用于 CLI 构建 TypeScript CLI 应用程序的标准化库

## 安装

```sh
npm install @cloud-copilot/cli
```

也可以使用：`pnpm add @cloud-copilot/cli`、`yarn add @cloud-copilot/cli`、`bun add @cloud-copilot/cli`

## README

# 国 际

[![NPM Version](https://img.shields.io/npm/v/@cloud-copilot/cli.svg?logo=nodedotjs)](https://www.npmjs.com/package/@cloud-copilot/cli) [![MIT License](https://img.shields.io/github/license/cloud-copilot/cli)](https://npmcn.com/package/%40cloud-copilot/cli/LICENSE.txt)

[![GuardDog](https://github.com/cloud-copilot/cli/actions/workflows/guarddog.yml/badge.svg)](https://github.com/cloud-copilot/cli/actions/workflows/guarddog.yml) [![Known Vulnerabilities](https://snyk.io/test/github/cloud-copilot/cli/badge.svg?targetFile=package.json&style=flat-square)](https://snyk.io/test/github/cloud-copilot/cli?targetFile=package.json)

使用Typescript规范工作国家清单的公用事业.

-   规范子命令、参数和操作方法
-   包括子命令和参数的"前缀匹配",所以用户只需匹配一个子命令或参数即可提供部分名称
-   允许用户以环境变量默认参数
-   自动为用户生成帮助文本
-   提供解析参数的安全响应类型
-   没有依赖关系
-   用于字符串、数字、布尔、enum、数组和地图类型的内置参数类型
-   简单自定义参数类型以创建自己的参数类型
-   Async 参数验证和版本检查
-   自动检查更新到您的 CLI

我写这封信是因为我正在构建几个CLI应用程序, 想要对用户可以信赖的参数进行标准解析.

我灵感来自 [https://github.com/lirantal/nodejs-cli-apps-best-practices 互联网档案馆的存檔,存档日期2013-12-22](https://github.com/lirantal/nodejs-cli-apps-best-practices) 财务报告和审定财务报表 [https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1 chap12.html 页面存档备份,存于互联网档案馆](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html) 遵循接受论据和环境变量的最佳做法,同时使我的范围极为有限,没有依赖性.

## 目录

-   [示例](https://npmcn.com/package/%40cloud-copilot/cli/#readme-example)
-   [安装](https://npmcn.com/package/%40cloud-copilot/cli/#readme-installation)
-   [文档](https://npmcn.com/package/%40cloud-copilot/cli/#readme-documentation)
    -   [核心指南](https://npmcn.com/package/%40cloud-copilot/cli/#readme-core-guides)
    -   [实例](https://npmcn.com/package/%40cloud-copilot/cli/#readme-examples)

## 文档

### 核心指南

-   **[开始](https://npmcn.com/package/%40cloud-copilot/cli/docs/GettingStarted.md)** - 为新用户提供完整的辅导
-   **[分析参考](https://npmcn.com/package/%40cloud-copilot/cli/docs/ParsingReference.md)** - 详细解析规则和力学
-   **[操作指南](https://npmcn.com/package/%40cloud-copilot/cli/docs/OperandsGuide.md)** - 处理立场辩论和预期操作
-   **[子命令指南](https://npmcn.com/package/%40cloud-copilot/cli/docs/SubcommandsGuide.md)** - 建立有分指令的CLI
-   **[自定义参数](https://npmcn.com/package/%40cloud-copilot/cli/docs/CustomArguments.md)** - 创建有验证的自定义参数类型
-   **[环境变量](https://npmcn.com/package/%40cloud-copilot/cli/docs/EnvironmentVariables.md)** - 环境可变一体化
-   **[版本处理](https://npmcn.com/package/%40cloud-copilot/cli/docs/VersionHandling.md)** - 版本管理和更新检查
-   **[API 参考](https://npmcn.com/package/%40cloud-copilot/cli/docs/APIReference.md)** - API文档

### [实例](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/README.md)

-   **[基本国家行动倡议](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/basic.ts)** - 带有版本处理的最小CLI设置
-   **[参数演示](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/arguments.ts)** - 所有参数类型,包括自定义日期参数
-   **[操作演示](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/operands.ts)** - 处理立场辩论(操作)
-   **[无操作演示](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/noOperands.ts)** - 仅接受旗帜和选项的国别学习水平
-   **[子命令Demo](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/subcommands.ts)** - 具有多个子命令和参数的CLI
-   **[版本处理](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/version.ts)** - 版本检查和更新通知
-   **[从 stdin 读取](https://npmcn.com/package/%40cloud-copilot/cli/src/demo/stdin.ts)** - 处理 Stdin 输入

## 示例

```typescript
import {
  parseCliArguments,
  stringArgument,
  stringArrayArgument,
  booleanArgument,
  numberArgument,
  enumArgument
} from '@cloud-copilot/cli'

const cli = await parseCliArguments(
  'my-command',
  // optional subcommands
  {
    init: {
      description: 'Initialize the project',
      // Subcommand Specific Arguments
      arguments: {
        s3: booleanArgument({
          description: 'Use S3 as the storage',
          character: 's'
        }),
        language: enumArgument({
          description: 'The language to use',
          validValues: ['typescript', 'javascript']
        })
      }
    },
    download: {
      description: 'Download a file',
      // Subcommand Specific Arguments
      arguments: {
        url: stringArgument({
          description: 'The URL to download from'
        })
      }
    }
  },
  // Global Arguments that apply to all subcommands
  {
    regions: stringArrayArgument({
      description: 'Regions to deploy to'
    }),
    account: stringArgument({
      description: 'AWS account to deploy to'
    }),
    ssl: booleanArgument({
      description: 'Enable SSL',
      character: 's'
    }),
    port: numberArgument({
      description: 'Port to use'
    })
  },
  {}
)
```

这将自动从命令行中拉出参数并验证它们 。 如果任何参数无效,它会随错误的信息一起出错. 如果所有参数和子命令都有效,它将返回一个带有类型安全响应的对象.

```typescript
cli.subcommand // 'init' | 'download' | undefined
cli.args.regions // string[] | undefined
cli.args.account // string | undefined
cli.args.ssl // boolean
cli.args.port // number | undefined

cli.anyValues // boolean, whether any values were provided on the CLI

if (cli.subcommand === 'init') {
  // Type Checked command specific arguments only in the return type if the subcommand is selected
  cli.args.s3 // boolean
  cli.args.language // 'typescript' | 'javascript' | undefined
}

if (cli.subcommand === 'download') {
  cli.args.url // string | undefined
}
```

如果用户提供 `--help` 将用可用的子命令和参数打印帮助信息.

## 安装

```bash
npm install @cloud-copilot/cli
```

## 常见问题

### @cloud-copilot/cli 是什么？

用于 CLI 构建 TypeScript CLI 应用程序的标准化库

### 如何安装 @cloud-copilot/cli？

在项目目录运行 npm install @cloud-copilot/cli，或使用 pnpm add / yarn add / bun add。

### @cloud-copilot/cli 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @cloud-copilot/cli 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @cloud-copilot/cli 可以商用吗？

@cloud-copilot/cli 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @cloud-copilot/cli 的下载量有多少？

根据 npm 官方下载统计，@cloud-copilot/cli 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,857 次，日均约 162 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @cloud-copilot/cli 还在维护吗？

最新版本 0\.2\.66 发布于 2026/08/29（2 个月前）；至今共发布 106 个版本，其中过去 12 个月发布了 48 个；首次发布于 2025/01/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

