python-cli

Builds command-line interfaces for Python projects using Click or Typer.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill python-cli-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-cli
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/python/cli
Command: npx skills add https://github.com/asarchami/dotfiles --skill python-cli-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires click.

What problem does it solve? Building a well-structured command-line interface in Python involves many decisions: framework choice, argument parsing, entry point configuration, progress feedback, shell completion, and testing. This Skill provides ready-made patterns and checklists so you can ship a polished CLI without researching each piece from scratch. ## Core Features & Use Cases - Framework Guidance: Compares Click, Typer, and argparse so you pick the right tool for your project. - Ready-Made Patterns: Includes command groups, argument and option handling, stdin/stdout file I/O, progress bars, and colored output. - Packaging & Testing: Shows pyproject.toml entry point configuration and CLI testing with Click's CliRunner. - Use Case: You are building a standalone data-processing tool and need subcommands, a --version flag, shell completion, and automated tests for every command. ## Quick Start Ask the AI to scaffold a Click-based CLI with a command group, a process subcommand accepting an input file, and CliRunner tests for it.

Frequently Asked Questions about python-cli

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a CLI in Python with Click?

Define a click.group() as the entry point, then attach subcommands with @cli.command() decorators using click.argument and click.option for parameters. Register the group in pyproject.toml under [project.scripts] to create an executable command.

Click vs Typer vs argparse: which Python CLI framework should I use?

Click is mature with extensive features and is the recommended default. Typer is modern and type-hint focused, built on Click. argparse has zero dependencies since it ships with the standard library, suiting minimal scripts.

How do I test a Click CLI application?

Use click.testing.CliRunner to invoke commands in tests without a real terminal. Call runner.invoke(cli, ['command', 'arg']) and assert on result.exit_code and result.output to verify behavior, including error cases.

How do I add shell completion to a Python CLI?

Click generates completion scripts via environment variables. Run _MYCLI_COMPLETE=bash_source mycli for Bash or _MYCLI_COMPLETE=zsh_source mycli for Zsh, and save the output to a completion file sourced by your shell.

How do I support stdin and stdout in a Python CLI?

Use click.File('r') and click.File('w') argument types with '-' as the default value. This lets users pipe data through your tool or pass file paths interchangeably, following standard Unix conventions.