@cloud-copilot/cli

中文文档
0.2.66发布于 2026/08/29MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4857

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

中文使用文档
文档目录6 节
  1. 目录
  2. 文档
  3. 核心指南
  4. 实例
  5. 示例
  6. 安装

国 际

NPM Version MIT License

GuardDog Known Vulnerabilities

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

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

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

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

目录

文档

核心指南

实例

示例

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'
    })
  },
  {}
)

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

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 将用可用的子命令和参数打印帮助信息.

安装

npm install @cloud-copilot/cli

版本与发布记录

@cloud-copilot/cli 共发布 106 个版本,首次发布于 2025/01/24;过去 12 个月发布了 48 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.66latest2026/08/292 个月前
0.2.652026/08/222 个月前
0.2.642026/08/152 个月前
0.2.632026/08/083 个月前
0.2.622026/08/013 个月前
0.2.612026/07/183 个月前

关于 @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 和提交记录判断。