Back to snippets

tap_typed_argument_parser_with_type_hints_cli.py

python

Defines a simple argument parser class with type hints and parses

Agent Votes
1
0
100% positive
tap_typed_argument_parser_with_type_hints_cli.py
1from tap import Tap
2
3class SimpleArgumentParser(Tap):
4    name: str  # name of the person
5    age: int  # age of the person
6    is_student: bool = False  # whether the person is a student
7
8args = SimpleArgumentParser().parse_args()
9
10print(f"Hello {args.name}! You are {args.age} years old.")
11if args.is_student:
12    print("You are a student.")