Use when building CLI tools, implementing argument parsing, or adding interactive prompts. Invoke for parsing flags and subcommands, displaying progress bars and spinners, generating bash/zsh/fish completion scripts, CLI design, shell completions, and cross-platform terminal applications using commander, click, typer, or cobra.
git clone https://github.com/Jeffallan/claude-skills.git--- name: cli-developer description: Use when building CLI tools, implementing argument parsing, or adding interactive prompts. Invoke for parsing flags and subcommands, displaying progress bars and spinners, generating bash/zsh/fish completion scripts, CLI design, shell completions, and cross-platform terminal applications using commander, click, typer, or cobra. license: MIT metadata: author: https://github.com/Jeffallan version: "1.1.0" domain: devops triggers: CLI, command-line, terminal app, argument parsing, shell completion, interactive prompt, progress bar, commander, click, typer, cobra role: specialist scope: implementation output-format: code related-skills: devops-engineer --- # CLI Developer ## Core Workflow 1. **Analyze UX** — Identify user workflows, command hierarchy, common tasks. Validate by listing all commands and their expected `--help` output before writing code. 2. **Design commands** — Plan subcommands, flags, arguments, configuration. Confirm flag naming is consistent and no existing signatures are broken. 3. **Implement** — Build with the appropriate CLI framework for the language (see Reference Guide below). After wiring up commands, run `<cli> --help` to verify help text renders correctly and `<cli> --version` to confirm version output. 4. **Polish** — Add completions, help text, error messages, progress indicators. Verify TTY detection for color output and graceful SIGINT handling. 5. **Test** — Run cross-platform smoke tests; benchmark startup time (target: <50ms). ## Reference Guide Load detailed guidance based on context: | Topic | Reference | Load When | |-------|-----------|-----------| | Design Patterns | `references/design-patterns.md` | Subcommands, flags, config, architecture | | Node.js CLIs | `references/node-cli.md` | commander, yargs, inquirer, chalk | | Python CLIs | `references/python-cli.md` | click, typer, argparse, rich | | Go CLIs | `references/go-cli.md` | cobra, viper, bubbletea | | UX Patterns | `references/ux-patterns.md` | Progress bars, colors, help text | ## Quick-Start Example ### Node.js (commander) ```js #!/usr/bin/env node // npm install commander const { program } = require('commander'); program .name('mytool') .description('Example CLI') .version('1.0.0'); program .command('greet <name>') .description('Greet a user') .option('-l, --loud', 'uppercase the greeting') .action((name, opts) => { const msg = `Hello, ${name}!`; console.log(opts.loud ? msg.toUpperCase() : msg); }); program.parse(); ``` For Python (click/typer) and Go (cobra) quick-start examples, see `references/python-cli.md` and `references/go-cli.md`. ## Constraints ### MUST DO - Keep startup time under 50ms - Provide clear, actionable error messages - Support `--help` and `--version` flags - Use consistent flag naming conventions - Handle SIGINT (Ctrl+C) gracefully - Validate user input early - Support both interactive and non-interactive modes - Test on Windows, macOS, and Linux ### MUST NOT DO - **Block on synchronous I/O unnecessarily** — use async reads or stream processing instead. - **Print to stdout when output will be piped** — write logs/diagnostics to stderr. - **Use colors when output is not a TTY** — detect before applying color: ```js // Node.js const useColor = process.stdout.isTTY; ``` ```python # Python import sys use_color = sys.stdout.isatty() ``` ```go // Go import "golang.org/x/term" useColor := term.IsTerminal(int(os.Stdout.Fd())) ``` - **Break existing command signatures** — treat flag/subcommand renames as breaking changes. - **Require interactive input in CI/CD environments** — always provide non-interactive fallbacks via flags or env vars. - **Hardcode paths or platform-specific logic** — use `os.homedir()` / `os.UserHomeDir()` / `Path.home()` instead. - **Ship without shell completions** — all three frameworks above have built-in completion generation. ## Output Templates When implementing CLI features, provide: 1. Command structure (main entry point, subcommands) 2. Configuration handling (files, env vars, flags) 3. Core implementation with error handling 4. Shell completion scripts if applicable 5. Brief explanation of UX decisions ## Knowledge Reference CLI frameworks (commander, yargs, oclif, click, typer, argparse, cobra, viper), terminal UI (chalk, inquirer, rich, bubbletea), testing (snapshot testing, E2E), distribution (npm, pip, homebrew, releases), performance optimization [Documentation](https://jeffallan.github.io/claude-skills/skills/devops/cli-developer/)
[{"step":"Define the CLI tool's purpose and required arguments. Use [ARGUMENTS] in the prompt template to specify flags, subcommands, or positional arguments. For example, `[ARGUMENTS]: input_file --input, output_dir --output, verbose --verbose`.","tip":"Start with a minimal set of arguments and expand as needed. Use `typer.Argument` for required inputs and `typer.Option` for optional flags."},{"step":"Choose a library for argument parsing and CLI design. Replace `[LIBRARY]` in the prompt with options like `Click` (Python), `Cobra` (Go), or `Commander` (Node.js). Specify the language in `[LANGUAGE]`.","tip":"For Python, `Typer` is recommended for its simplicity and integration with `rich` for progress bars and prompts. For Go, `Cobra` is widely used in tools like `kubectl`."},{"step":"Add features like progress bars, interactive prompts, or shell completions. Replace `[FEATURES]` with specifics like `progress bars, interactive prompts, and bash completion scripts`.","tip":"Use libraries like `rich` (Python) or `progressbar2` for progress tracking. For shell completions, most modern CLI libraries support generating scripts for bash, zsh, and fish."},{"step":"Test the CLI tool locally. Run commands like `python cli.py --help` or `./cli-tool --version` to verify functionality. Generate shell completions using the tool's built-in commands (e.g., `--install-completion`).","tip":"Use `typer.echo` or `print` for debugging. For shell completions, test in a new terminal session to ensure they load correctly."},{"step":"Package and distribute the CLI tool. For Python, create a `setup.py` or `pyproject.toml` file. For Go, use `go build` to generate a binary. Share the tool via package managers or repositories.","tip":"Include a `README.md` with installation and usage instructions. For shell completions, provide clear instructions for users to install them."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/Jeffallan/claude-skills/tree/main/skills/cli-developerCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Build a CLI tool in [LANGUAGE] that parses the following command-line arguments: [ARGUMENTS]. The tool should include [FEATURES] such as subcommands, progress bars, interactive prompts, or shell completion scripts. Use [LIBRARY] (e.g., Click, Typer, Cobra) for argument parsing. Ensure the output is user-friendly and follows CLI best practices.
Here’s a complete Python CLI tool using the `Typer` library that parses arguments, includes subcommands, and generates shell completion scripts. The tool, named `data-processor`, is designed to handle data processing tasks with progress tracking and interactive prompts.
```python
import typer
from rich.progress import track
from typing import Optional
app = typer.Typer()
@app.command()
def process(
input_file: str = typer.Argument(..., help="Path to the input file"),
output_dir: str = typer.Option("./output", help="Directory to save processed files"),
verbose: bool = typer.Option(False, help="Enable verbose output"),
batch_size: int = typer.Option(1000, help="Number of records to process at once"),
interactive: bool = typer.Option(False, help="Enable interactive mode")
):
"""Process a dataset and save results to the specified directory."""
typer.echo(f"Processing file: {input_file}")
typer.echo(f"Output directory: {output_dir}")
typer.echo(f"Batch size: {batch_size}")
if interactive:
confirm = typer.confirm("Do you want to proceed?", default=True)
if not confirm:
typer.echo("Operation cancelled.")
raise typer.Abort()
# Simulate processing with a progress bar
for i in track(range(10), description="Processing batches..."):
if verbose:
typer.echo(f"Processed batch {i + 1}/{10}")
typer.echo("Processing complete!")
@app.command()
def validate(input_file: str = typer.Argument(..., help="Path to the file to validate")):
"""Validate the integrity of a dataset."""
typer.echo(f"Validating file: {input_file}")
# Simulate validation
for i in track(range(5), description="Validating records..."):
pass
typer.echo("Validation complete. No errors found.")
if __name__ == "__main__":
app()
```
To install the CLI tool and generate shell completions, run:
```bash
pip install typer rich
pip install -e . # Install the CLI tool in development mode
# Generate and install completions for bash
_data-processor --install-completion
```
Example usage:
```bash
data-processor process data.csv --output-dir ./results --batch-size 500 --interactive
data-processor validate data.csv
```skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan