@cloud-copilot/cli

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

A standardized library for CLI building TypeScript CLI applications

原始使用文档
文档目录6 节
  1. Table of Contents
  2. Documentation
  3. Core Guides
  4. Examples
  5. Example
  6. Installation

CLI

NPM Version MIT License

GuardDog Known Vulnerabilities

Utilities for standardizing working CLIs in Typescript.

  • Standardizes the way subcommands, arguments, and operands are parsed and validated
  • Includes "prefix matching" of subcommands and arguments, so users can provide partial names if they match only one subcommand or argument
  • Allows users to default arguments with environment variables
  • Automatically generates a help text for the user
  • Provides a type safe response of the parsed arguments
  • Has zero dependencies
  • Built-in argument types for string, number, boolean, enum, array, and map types
  • Easy custom argument types to create your own argument types with validation
  • Async argument validation and version checking
  • Automatic version checking for updates to your CLI

I wrote this because I'm building several CLI applications and want to have a standard parsing of arguments that users can rely on across all of them.

I was inspired by https://github.com/lirantal/nodejs-cli-apps-best-practices and https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html to follow best practices for accepting arguments and environment variables while keeping my scope extremely limited and having no dependencies.

Table of Contents

Documentation

Core Guides

Examples

Example

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

This will automatically pull in the arguments from the command line and validate them. If any arguments are not valid, it will throw an error with the message of what is wrong. If all arguments and subcommands are valid, it will return an object with a type safe response.

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
}

If the user provides --help a help message will be printed out with the available subcommands and arguments.

Installation

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 是什么?

A standardized library for CLI building TypeScript CLI applications

如何安装 @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 和提交记录判断。