cli-conventions

Standardize argparse CLI flags, subcommands, and output conventions.

Updated Apr 11, 2026
One-click install
npx skills add https://github.com/bennybennison/agent-toolkit --skill cli-conventions-bennybennison
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cli-conventions
Source: https://github.com/bennybennison/agent-toolkit/tree/main/skills/cli-conventions
Command: npx skills add https://github.com/bennybennison/agent-toolkit --skill cli-conventions-bennybennison

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Inconsistent command-line flags and subcommand patterns across Python tools cause user confusion, break automation scripts, and make CLIs hard to test and maintain. This Skill provides a compact, opinionated convention set to keep flags predictable, output machine-friendly, and parsers testable.

Core Features & Use Cases

  • Standardized reserved short flags for common behaviors (help, verbose, quiet, dry-run, force, output, config) to preserve developer and script expectations.
  • Parser construction guidance: separate build_parser from execution, use parent parsers for shared flags, and adopt subcommand handlers for clear dispatch.
  • Output and exit conventions that separate structured data to stdout and human/progress/error messages to stderr, plus explicit exit codes for usage and runtime errors.
  • Use cases include building a new argparse-based CLI, adding or reviewing subcommands for consistency, and preparing tools for reliable automation and piping workflows.

Quick Start

Build a reusable build_parser that registers the reserved flags and shared parent parsers, then call parse_args in main and dispatch to subcommand handlers.

Frequently Asked Questions about cli-conventions

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

FAQPage Schema
How do I structure an argparse CLI for consistent flags and subcommands?

To structure an argparse CLI for consistent flags, separate parser construction from execution using build_parser, use parent parsers for shared flags, and adopt subcommand handlers for clear dispatch and testable command-line tools.

What are the best practices for Python CLI stdout, stderr, and exit codes?

Python CLI best practices require separating structured data to stdout and human, progress, or error messages to stderr, while applying explicit exit codes to distinguish usage errors from runtime errors for reliable automation and piping.

How do I reserve short flags in argparse to avoid breaking automation scripts?

To reserve short flags in argparse, standardize common behaviors like help, verbose, quiet, dry-run, force, output, and config to preserve developer expectations and prevent breaking existing automation scripts across multiple Python CLI utilities.

Does separating parser construction from execution make Python CLIs easier to test?

Separating parser construction from execution makes Python CLIs easier to test by isolating argument parsing logic from command dispatch, allowing direct parser validation without triggering side effects or requiring full command-line environment setup.

Can I use parent parsers to share common flags across argparse subcommands?

You can use parent parsers in argparse to share common flags across subcommands, ensuring consistent command-line conventions without duplicating argument definitions, which keeps Python CLI tools maintainable and predictable for users.