Closed yarikoptic closed 3 weeks ago
@yarikoptic Unless duct
is calling parser.parse_intermixed_args()
, I think it should stop at the first non-option argument by default.
duct is using parser.parse_args()
https://github.com/con/duct/blob/0eec46d9c7527a7f17d3205447223f27b622aa87/src/duct.py#L271
not quite -- it does consume [arguments]
and spits out error, e.g. we get
for
yoh@typhon:/tmp/repro-TccSlQF/ds000003-qc$ cat .datalad/config
[datalad "dataset"]
id = 621f77c3-4a35-4147-8146-67fa49b66369
[datalad "containers.bids-mriqc"]
image = containers/images/bids/bids-mriqc--0.16.0.sing
cmdexec = duct {img_dspath}/containers/scripts/singularity_cmd run {img} {cmd}
in repronim/containers - I had to add --
after duct there
Then try parse_known_args()
instead.
parese_known_args does work but at first glance (not thorough) it seems like there wouldn't be any way to pass args to the inner command that happen to have the same name as a duct
arg.
Is there a reason you need to use argparse in the first place? Click is really the better option for both this sort of thing and in general.
We wanted duct to be "pure" to be as portable as possible.
The undocumented nargs
value argparse.REMAINDER
should do what you want:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--foo")
parser.add_argument("rest", nargs=argparse.REMAINDER)
print(parser.parse_args(["bar", "--foo", "quux"]))
# Prints: Namespace(foo=None, rest=['bar', '--foo', 'quux'])
so instead of
looks like
and add description on
--
as to be recommended to ensure thatarguments
are not treated as arguments toduct
.On the other hand, I think we might need to look into how to tune argparser here: ideally we should automagically stop parsing when reaching
command
. @jwodder , you did some heavy CLI parsing tune up in datalad-installer, may be you know what would be the best way here to ensure that parsing stops and[arguments]
for thecommand
do not interfer with ourduct
arguments?