create-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create CLI

创建CLI工具

Design CLI surface area: syntax, flags, output, error handling.
设计CLI的交互范围:语法、标志、输出、错误处理。

Conventions

约定规范

  • Long options preferred (
    --from
    not
    -f
    )
  • stdout for data, stderr for progress/errors
  • Exit codes: 0=success, 1=runtime error, 2=usage error
  • Include
    --help
    ,
    --json
    ,
    --quiet
  • Validate early, fail fast
  • 优先使用长选项(
    --from
    而非
    -f
  • stdout用于输出数据,stderr用于输出进度/错误信息
  • 退出码:0=成功,1=运行时错误,2=使用错误
  • 包含
    --help
    --json
    --quiet
    选项
  • 尽早验证,快速失败

Output

输出

  • Default: human-readable tables
  • --json
    : JSON output (implies quiet)
  • --quiet
    : suppress progress
  • Respect
    NO_COLOR
    env
  • 默认:人类可读的表格格式
  • --json
    :输出JSON格式(自动启用静默模式)
  • --quiet
    :抑制进度输出
  • 遵循
    NO_COLOR
    环境变量设置

Errors

错误

<name>: <message>
Try '<name> --help'
<name>: <message>
Try '<name> --help'

Destructive Operations

破坏性操作

  • Confirm when stdin is TTY
  • --force
    to skip confirmation
  • --dry-run
    to preview
  • 当标准输入为TTY时进行确认
  • --force
    跳过确认
  • --dry-run
    预览操作

Help Format

帮助信息格式

<name> - <one-line description>

USAGE
    <name> [OPTIONS] <ARGS>

OPTIONS
    --option <VALUE>    Description [default: X]
    --help              Show this help

EXAMPLES
    <name> arg1 arg2

See references/node-js.md - Node.js with parseArgs See references/python-uv.md - Python with uv
See clig.dev for comprehensive guidelines.
<name> - <one-line description>

USAGE
    <name> [OPTIONS] <ARGS>

OPTIONS
    --option <VALUE>    描述 [默认值: X]
    --help              显示此帮助信息

EXAMPLES
    <name> arg1 arg2

查看references/node-js.md - 使用parseArgs的Node.js实现 查看references/python-uv.md - 使用uv的Python实现
查看clig.dev获取全面指南。