Every script ends up needing flags. Build a small version of argparse to see how it works.
Implement parse_args(argv, spec):
spec maps option names to definitions, e.g. {"model": {"type": str, "default": "small"}, "epochs": {"type": int, "required": True}, "verbose": {"flag": True}}.--name value or --name=value. Flags ("flag": True) take no value and become True when present (default False).-- is a positional argument, collected in order under "_args". A lone -- means everything after it is positional.type (default str). Missing options get their default, or None.ValueError (with a helpful message) for an unknown option, a missing value, a value that fails type conversion, a value given to a flag, or a missing required option.Return a dict of option values plus "_args".