Multi-Command Python CLI Tool Scaffold Prompt
Design a production-ready Python CLI tool with subcommands, global flags, config-file precedence, machine-readable output, and clean exit codes that an ops team can extend without rework.
- Target user
- Engineers building reusable internal CLI tooling
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who designs internal CLI tools that teams actually adopt. Favor predictable UX, scriptability, and easy extension over framework magic. I will provide: - The tool's purpose and the 2–4 subcommands it should ship with (e.g., `list`, `apply`, `status`) - Where config comes from (flags, env vars, a config file) and the precedence I want - Whether output must be consumable by other scripts (JSON) and any auth/secret it needs Your job: 1. **Pick the structure** — use `argparse` subparsers (or `click`/`typer` if I allow deps) with one handler function per subcommand and shared global flags (`--config`, `--json`, `-v`, `--dry-run`) defined once via a parent parser. 2. **Resolve config precedence** — explicit flag > environment variable > config file > built-in default, resolved in one clearly documented place. Never read secrets from argv (they leak into `ps`/shell history). 3. **Standardize output** — human-readable by default, `--json` for machines, with errors and diagnostics on stderr only so stdout stays pipe-safe. 4. **Use real exit codes** — 0 success, 1 expected failure, 2 usage error; document each so callers can branch on them. 5. **Make it extensible** — show exactly how to add a new subcommand (one function + one registration) and where to put shared logic. 6. **Package it** — give a `pyproject.toml` `[project.scripts]` entry point so it installs as a real command. Output: the CLI module(s), the config-precedence resolver, the packaging snippet, and a usage transcript covering one happy path, one usage error, and one `--json` run.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Python Typer CLI App Scaffold Prompt
Generate a modern, type-hint-driven CLI using Typer — subcommands, validated options, rich help, shell completion, and clean exit codes — for operations tools that need to feel like first-class CLIs.
-
Asyncio TaskGroup Structured-Concurrency Python Script Prompt
Write a Python 3.11+ automation script that fans work out with asyncio.TaskGroup so failures cancel siblings cleanly, errors aggregate into an ExceptionGroup, and no task is ever silently orphaned.
-
Convert a Fragile Bash Pipeline to Python Prompt
Rewrite an overgrown, fragile Bash script full of pipes, subshells, and string parsing into a maintainable Python program with proper error handling, types, and tests.
-
Add Pytest Coverage to an Automation Script Prompt
Wrap an existing Python automation script in a pytest suite that mocks subprocess, network, filesystem, and clock side effects so the logic is tested fast and deterministically without touching real systems.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.