cli-developer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CLI Developer

CLI 开发者

Purpose

用途

Provides expertise in building robust, user-friendly command-line applications and terminal interfaces. Covers argument parsing, interactive prompts, TUI frameworks, and shell automation across multiple languages.
提供构建健壮、易用的命令行应用和终端界面的专业能力。涵盖多语言下的参数解析、交互式提示、TUI框架以及Shell自动化相关内容。

When to Use

适用场景

  • Building CLI applications in any language
  • Creating interactive terminal user interfaces
  • Implementing command-line argument parsing
  • Building shell scripts and automation tools
  • Adding progress bars, spinners, and colors
  • Creating REPL-style applications
  • Distributing CLI tools as packages
  • 用任意语言构建CLI应用
  • 创建交互式终端用户界面
  • 实现命令行参数解析
  • 构建Shell脚本与自动化工具
  • 添加进度条、加载动画与彩色输出
  • 创建REPL风格的应用
  • 将CLI工具打包分发

Quick Start

快速入门

Invoke this skill when:
  • Building CLI applications in any language
  • Creating interactive terminal user interfaces
  • Implementing command-line argument parsing
  • Building shell scripts and automation tools
  • Creating REPL-style applications
Do NOT invoke when:
  • Building GUI desktop applications (use windows-app-developer)
  • Creating web-based interfaces (use frontend skills)
  • Writing PowerShell-specific tools (use powershell skills)
  • Building mobile applications (use mobile-developer)
在以下场景调用此技能:
  • 用任意语言构建CLI应用
  • 创建交互式终端用户界面
  • 实现命令行参数解析
  • 构建Shell脚本与自动化工具
  • 创建REPL风格的应用
请勿在以下场景调用:
  • 构建GUI桌面应用(请使用windows-app-developer技能)
  • 创建基于Web的界面(请使用前端技能)
  • 编写PowerShell专属工具(请使用powershell技能)
  • 构建移动应用(请使用mobile-developer技能)

Decision Framework

决策框架

CLI Framework Selection:
├── Node.js → Commander.js, Yargs, Oclif
├── Python → Click, Typer, argparse
├── Go → Cobra, urfave/cli
├── Rust → Clap, structopt
├── TUI needed
│   ├── Node.js → Ink, Blessed
│   ├── Python → Textual, Rich
│   ├── Go → Bubbletea, tview
│   └── Rust → Ratatui, crossterm
└── Simple script → Shell (bash/zsh)
CLI Framework Selection:
├── Node.js → Commander.js, Yargs, Oclif
├── Python → Click, Typer, argparse
├── Go → Cobra, urfave/cli
├── Rust → Clap, structopt
├── TUI needed
│   ├── Node.js → Ink, Blessed
│   ├── Python → Textual, Rich
│   ├── Go → Bubbletea, tview
│   └── Rust → Ratatui, crossterm
└── Simple script → Shell (bash/zsh)

Core Workflows

核心工作流程

1. CLI Application Setup

1. CLI应用搭建

  1. Choose framework based on language/needs
  2. Define command structure and subcommands
  3. Implement argument and option parsing
  4. Add input validation and help text
  5. Implement core command logic
  6. Add output formatting (JSON, table, etc.)
  7. Package for distribution
  1. 根据开发语言/需求选择框架
  2. 定义命令结构与子命令
  3. 实现参数与选项解析
  4. 添加输入验证与帮助文本
  5. 实现核心命令逻辑
  6. 添加输出格式化(JSON、表格等)
  7. 打包用于分发

2. Interactive TUI Development

2. 交互式TUI开发

  1. Select TUI framework
  2. Design screen layout and components
  3. Implement input handling and navigation
  4. Add state management
  5. Handle terminal resize events
  6. Test across different terminal emulators
  1. 选择TUI框架
  2. 设计屏幕布局与组件
  3. 实现输入处理与导航
  4. 添加状态管理
  5. 处理终端窗口大小调整事件
  6. 在不同终端模拟器中测试

3. CLI Distribution

3. CLI工具分发

  1. Add proper versioning
  2. Create man pages or help docs
  3. Package for target platforms
  4. Set up installation via package managers
  5. Create shell completions
  6. Add update mechanism
  1. 添加规范的版本控制
  2. 创建手册页或帮助文档
  3. 针对目标平台打包
  4. 配置通过包管理器安装
  5. 创建Shell补全脚本
  6. 添加更新机制

Best Practices

最佳实践

  • Follow POSIX conventions for flags and arguments
  • Provide both short (-v) and long (--verbose) options
  • Include --help and --version flags
  • Use exit codes properly (0 for success)
  • Support piping and stdin input
  • Add shell completion scripts
  • 遵循POSIX规范设置标志与参数
  • 同时提供短选项(-v)与长选项(--verbose)
  • 包含--help和--version标志
  • 正确使用退出码(0表示成功)
  • 支持管道与标准输入
  • 添加Shell补全脚本

Anti-Patterns

反模式

Anti-PatternProblemCorrect Approach
No help textUsers can't discover commandsAdd comprehensive --help
Silent failuresUsers don't know what went wrongClear error messages + exit codes
Hard-coded pathsBreaks on other systemsUse environment variables, XDG
No stdin supportCan't pipe dataSupport reading from stdin
Colored output to pipesBreaks parsingDetect TTY, disable colors for pipes
反模式问题正确做法
无帮助文本用户无法了解可用命令添加全面的--help功能
静默失败用户不知道出现了什么问题清晰的错误提示 + 退出码
硬编码路径在其他系统上无法正常运行使用环境变量、XDG规范
不支持标准输入无法通过管道传输数据支持从标准输入读取内容
向管道输出彩色内容导致解析失败检测TTY,向管道输出时禁用彩色