Open kddubey opened 2 months ago
The name-collision issue is weird. Play w/ this argparse
script:
# demo_names.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", default=0, type=int)
subparsers = parser.add_subparsers(dest="parser_name")
parser_lan = subparsers.add_parser("car")
parser_lan.add_argument("--boo")
parser_lan.add_argument("--verbose") # collides w/ name in the main parser
parser_serial = subparsers.add_parser("bus")
parser_serial.add_argument("--fun")
print(parser.parse_args())
For example, running—
python demo_names.py --verbose 1 car --boo booval
outputs:
Namespace(verbose=None, parser_name='car', boo='booval')
Seems unexpected.
Not sure how to handle it: be consistent w/ argparse
behavior, or attempt to fix it by separating the namespaces for the main parser and subparsers as in, e.g., here. Or (what I think I'll go with for now) raise an error
Fix #101
Not ready for a full review yet, but I'd appreciate feedback on the overall approach
I'll do all of the
# TODO:
s and add tests soonI'll also study
fire.Fire
's interface and behavior a bit more to understand what ppl want out of this type of feature