Here's a subsection of my parser configuration
parser.add_argument(
'infile', help="The file to be imported",
type=argparse.FileType('r'), default=sys.stdin
)
parser.add_argument(
'--carpark', nargs='+', dest='CarparkID', type=int, default=[],
help="One or many carpark IDs"
)
However, the --carpark
argument seems to be too greedy and eats anything that follows it:
$ mycommand --carpark 17 ~/path-to-file
mycommand: error: argument --carpark: invalid int value: '/home/oli/path-to-file'
What's a good way around something like this? I need to pass a list of integer IDs into the command but also have a positional file (which can also be stdin).
Is there —for example— a non-greedy nargs
option that will only parse as much of this as makes sense?