I have the following code
parser = argparse.ArgumentParser(allow_abbrev=False, add_help=False)
parser.add_argument('--conf', nargs=1)
parser.add_argument('-h', '--help', nargs='?', const='generic')
parser.add_argument('-v', '--version', action="store_true")
subparsers = parser.add_subparsers()
subparsers.required = False
parser_start = subparsers.add_parser('start')
group1 = parser_start.add_mutually_exclusive_group()
group1.add_argument('--quiet', action="store_true")
group1.add_argument('-V', '--verbose', nargs="*")
# parser_console = subparsers.add_parser('console')
print(argv)
parsed_args = parser.parse_known_args(argv)
Now, when I pass argv
as argv = ['abc', 'def']
or argv = ['abc']
I get
['abc', 'def']
usage: lbrynet [--conf CONF] [-h [HELP]] [-v] {start} ...
lbrynet: error: invalid choice: 'abc' (choose from 'start')
What I was expecting was to get ['abc', 'def']
in the tuple for unknown args.
I've checked a lot of stackoverflow answers(such as ans 1, ans 2, ans 3, ans 4) and bug reports(e.g. br 1) and a lot but I can't seem to find a way to do it. Is this an unsolved bug? Am I wrong in expecting that this can be done. If this can't be done are there any workarounds to doing this?
Also to clarify, the ['abc', 'def']
got from the tuple have to be passed to some other function to be processed.
Happy to provide any further clarifications and/or clear any ambiguities.