It is very non-intuitive that if you want to specify, say, the clock speed on the command line, you can say --clock-speed 100ms, but you can't say --clock-speed 100 ms. This is especially awkward when using words for units as in --min-time 1day.
I can see a couple of ways to handle this. The kludgier way would be to use nargs="*" for the argument and have ArgParse.parse_arg() do some sort of buffering on the strings it gets to try to figure out whether it got one or two arguments. If we do this, we might have to use a tuple for the metavar to get a reasonable usage message (i.e., one that didn't imply that we allowed multiple values when we only allow one). In any case, this would have to be specified on every use of a quantity argument.
The clean way is to define a proprietary action as a subclass of Action that looks at what it gets and decides whether to consume one or two arguments. This would also allow it to provide a format_usage() function that will allow usage messages to get the message across. This will probably also allow this to play well with nargs (or else to have several actions that mimic the various nargs values) as well as to have actions for normal actions such as append or extend.
Migrated from internal repository. Originally created by @EvanKirshenbaum on Feb 04, 2023 at 3:42 PM PST.
It is very non-intuitive that if you want to specify, say, the clock speed on the command line, you can say
--clock-speed 100ms
, but you can't say--clock-speed 100 ms
. This is especially awkward when using words for units as in--min-time 1day
.I can see a couple of ways to handle this. The kludgier way would be to use
nargs="*"
for the argument and haveArgParse.parse_arg()
do some sort of buffering on the strings it gets to try to figure out whether it got one or two arguments. If we do this, we might have to use a tuple for the metavar to get a reasonable usage message (i.e., one that didn't imply that we allowed multiple values when we only allow one). In any case, this would have to be specified on every use of a quantity argument.The clean way is to define a proprietary
action
as a subclass ofAction
that looks at what it gets and decides whether to consume one or two arguments. This would also allow it to provide aformat_usage()
function that will allow usage messages to get the message across. This will probably also allow this to play well withnargs
(or else to have several actions that mimic the variousnargs
values) as well as to have actions for normalaction
s such asappend
orextend
.Migrated from internal repository. Originally created by @EvanKirshenbaum on Feb 04, 2023 at 3:42 PM PST.