Pcornel
Automation · Python Automation

argparse

Cheat sheet · https://pcornel.dk/topic.php?topic=5263

Back to the Topic

Answer

argparse builds command-line interfaces for Python scripts, defining arguments, options, types, defaults and help text, so scripts can be run with clear parameters like --host and --dry-run.

Remember

  • argparse defines arguments, options and help.
  • Types and defaults validate input.
  • --help is generated automatically.

First checks

  • python3 script.py --help — usage
  • argparse with types and choices — validation
  • Subcommands — structure

Verify in this order

CLI args → argparse → validated namespace

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5263

Confirmation

Confirm action

Continue?