Create CLI
Design CLI surface area (syntax + behavior), human-first, script-friendly.
Do This First
- - Read
agent-scripts/skills/create-cli/references/cli-guidelines.md and apply it as the default rubric. - Upstream/full guidelines: https://clig.dev/ (propose changes: https://github.com/cli-guidelines/cli-guidelines)
- Ask only the minimum clarifying questions needed to lock the interface.
Clarify (fast)
Ask, then proceed with best-guess defaults if user is unsure:
- - Command name + one-sentence purpose.
- Primary user: humans, scripts, or both.
- Input sources: args vs stdin; files vs URLs; secrets (never via flags).
- Output contract: human text,
--json, --plain, exit codes. - Interactivity: prompts allowed? need
--no-input? confirmations for destructive ops? - Config model: flags/env/config-file; precedence; XDG vs repo-local.
- Platform/runtime constraints: macOS/Linux/Windows; single binary vs runtime.
Deliverables (what to output)
When designing a CLI, produce a compact spec the user can implement:
- - Command tree + USAGE synopsis.
- Args/flags table (types, defaults, required/optional, examples).
- Subcommand semantics (what each does; idempotence; state changes).
- Output rules: stdout vs stderr; TTY detection;
--json/--plain; --quiet/--verbose. - Error + exit code map (top failure modes).
- Safety rules:
--dry-run, confirmations, --force, --no-input. - Config/env rules + precedence (flags > env > project config > user config > system).
- Shell completion story (if relevant): install/discoverability; generation command or bundled scripts.
- 5–10 example invocations (common flows; include piped/stdin examples).
Default Conventions (unless user says otherwise)
- -
-h/--help always shows help and ignores other args. - INLINECODE12 prints version to stdout.
- Primary data to stdout; diagnostics/errors to stderr.
- Add
--json for machine output; consider --plain for stable line-based text. - Prompts only when stdin is a TTY;
--no-input disables prompts. - Destructive operations: interactive confirmation + non-interactive requires
--force or explicit --confirm=.... - Respect
NO_COLOR, TERM=dumb; provide --no-color. - Handle Ctrl-C: exit fast; bounded cleanup; be crash-only when possible.
Templates (copy into your answer)
CLI spec skeleton
Fill these sections, drop anything irrelevant:
- 1. Name: INLINECODE21
- One-liner: INLINECODE22
- USAGE:
-
mycmd [global flags] <subcommand> [args]
- 4. Subcommands:
-
mycmd init ...
-
mycmd run ...
- 5. Global flags:
-
-h, --help
-
--version
-
-q, --quiet /
-v, --verbose (define exactly)
-
--json /
--plain (if applicable)
- 6. I/O contract:
- stdout:
- stderr:
- 7. Exit codes:
-
0 success
-
1 generic failure
-
2 invalid usage (parse/validation)
- (add command-specific codes only when actually useful)
- 8. Env/config:
- env vars:
- config file path + precedence:
- 9. Examples:
- …
Notes
- - Prefer recommending a parsing library (language-specific) only when asked; otherwise keep this skill language-agnostic.
- If the request is “design parameters”, do not drift into implementation.
Create CLI
设计CLI表面区域(语法+行为),以人为本,同时兼顾脚本友好性。
首先执行
- - 阅读 agent-scripts/skills/create-cli/references/cli-guidelines.md 并将其作为默认评估标准。
- 上游/完整指南:https://clig.dev/(提出修改建议:https://github.com/cli-guidelines/cli-guidelines)
- 仅提出锁定接口所需的最少澄清性问题。
澄清(快速)
提问,如果用户不确定则采用最佳猜测默认值:
- - 命令名称 + 一句话用途说明。
- 主要用户:人类、脚本,或两者兼顾。
- 输入来源:参数 vs 标准输入;文件 vs URL;密钥(绝不要通过标志传递)。
- 输出约定:人类可读文本、--json、--plain、退出码。
- 交互性:是否允许提示?是否需要 --no-input?破坏性操作是否需要确认?
- 配置模型:标志/环境变量/配置文件;优先级顺序;XDG vs 仓库本地。
- 平台/运行时约束:macOS/Linux/Windows;单二进制 vs 运行时环境。
交付物(输出内容)
设计CLI时,生成用户可实现的紧凑规范:
- - 命令树 + USAGE 用法概要。
- 参数/标志表(类型、默认值、必选/可选、示例)。
- 子命令语义(每个命令的功能;幂等性;状态变更)。
- 输出规则:标准输出 vs 标准错误;TTY检测;--json/--plain;--quiet/--verbose。
- 错误 + 退出码映射(主要失败模式)。
- 安全规则:--dry-run、确认、--force、--no-input。
- 配置/环境变量规则 + 优先级(标志 > 环境变量 > 项目配置 > 用户配置 > 系统配置)。
- Shell补全说明(如相关):安装/可发现性;生成命令或捆绑脚本。
- 5-10个示例调用(常见流程;包含管道/标准输入示例)。
默认约定(除非用户另有说明)
- - -h/--help 始终显示帮助信息并忽略其他参数。
- --version 将版本信息输出到标准输出。
- 主要数据输出到标准输出;诊断信息/错误输出到标准错误。
- 添加 --json 用于机器输出;考虑 --plain 用于稳定的基于行的文本。
- 仅当标准输入为TTY时才显示提示;--no-input 禁用提示。
- 破坏性操作:交互式确认 + 非交互式需要 --force 或显式 --confirm=...。
- 尊重 NO_COLOR、TERM=dumb;提供 --no-color。
- 处理Ctrl-C:快速退出;有限清理;尽可能采用崩溃安全模式。
模板(复制到你的回答中)
CLI规范骨架
填写以下部分,删除不相关的内容:
- 1. 名称:mycmd
- 一句话说明:...
- 用法:
- mycmd [全局标志] <子命令> [参数]
- 4. 子命令:
- mycmd init ...
- mycmd run ...
- 5. 全局标志:
- -h, --help
- --version
- -q, --quiet / -v, --verbose(精确定义)
- --json / --plain(如适用)
- 6. 输入/输出约定:
- 标准输出:
- 标准错误:
- 7. 退出码:
- 0 成功
- 1 通用失败
- 2 无效用法(解析/验证)
- (仅在确实有用时添加命令特定代码)
- 8. 环境变量/配置:
- 环境变量:
- 配置文件路径 + 优先级:
- 9. 示例:
- …
备注
- - 仅在用户要求时推荐使用解析库(特定语言);否则保持此技能的语言无关性。
- 如果请求是设计参数,不要偏离到实现细节。