Objective

Build command-line tools with argument parsing.

Tools & Technologies

  • Python 3
  • argparse
  • click
  • sys.argv

Key Commands

parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true')
args = parser.parse_args()

Lab Steps

01
argparse Basics

Create a CLI parser with positional and optional arguments.

02
Subcommands

Implement subcommands (like git commit, git push) with subparsers.

03
Validation

Add type validation and choices to arguments.

04
Help Text

Write clear help strings and usage documentation.

Challenges Encountered

  • argparse error messages can be confusing for users
  • Subparser dest= is required for subcommand detection

Key Takeaways

  • click is more ergonomic than argparse for complex CLIs
  • Always test --help output before releasing a tool