- Home
- Skills
- Wdm0006
- Python Skills
- Cli Development
cli-development_skill
- Python
6
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill wdm0006/python-skills --skill cli-development- SKILL.md3.0 KB
Overview
This skill builds command-line interfaces for Python libraries using Click or Typer, providing patterns for command groups, argument handling, progress bars, shell completion, and testing. It packages ready-to-apply examples and a practical checklist so you can add robust CLI functionality to a library or create standalone command-line tools. The material emphasizes developer ergonomics, predictable UX, and testability.
How this skill works
The skill supplies example code and conventions: a Click-based group entry point, command definitions with arguments and options, file/stdin handling, progress bars, colored output, and error handling. It shows how to wire an entry point via pyproject.toml, enable shell completions, and exercise commands with Click's CliRunner for automated testing. Patterns are adaptable to Typer when you prefer type-hint-driven APIs.
When to use it
- Adding CLI commands to a Python library for developer or user workflows
- Building a standalone command-line tool that needs argument parsing and subcommands
- Needing consistent stdin/stdout behavior for pipes and scripts
- Implementing progress reporting and colored terminal output
- Automating CLI tests and verifying error handling and exit codes
Best practices
- Expose a single group entry point and declare it in pyproject.toml for easy installation
- Support '-' for stdin/stdout using click.File and document behavior
- Return non-zero exit codes and send error messages to stderr for scripting reliability
- Write tests with click.testing.CliRunner for normal and stdin scenarios
- Provide --help and --version for all commands and offer shell completion scripts
- Use click.progressbar and click.secho for consistent UX across platforms
Example use cases
- A data processing library that needs a CLI to run batch jobs and show progress
- A developer tool that wraps project tasks (format, lint, release) as subcommands
- A file converter that reads from stdin or a path and writes to stdout or a file
- A deployment helper that needs colored, human-friendly status messages
- Automated CI tests that invoke CLI commands and assert exit codes and output
FAQ
Use Click for mature, feature-rich control and Typer if you prefer modern type-hint-driven APIs; both can follow the same UX patterns shown here.
How do I test stdin-based commands?
Use click.testing.CliRunner and pass input as the input parameter, or invoke the command with '-' when you support click.File with default '-'.