Background
Many command-line utilities provide special handling for all arguments after a double dash (--
). Examples:
git diff
: All arguments after --
are paths (which can start with -
):
git diff [options] -- [path...]
Some wrapper tools use this to pass arbitrary arguments on to the tool they are wrapping -- even arguments which may conflict with their own!
foowrap -a -- -a
π ‘ π ‘
β ββββ Passed to wrapped tool
ββββββββββ Consumed by wrapper
Problem
How can we accomplish this using argparse
?
--
, consider removing only the first instance, with something likeif extra and extra[0] == '--': extra.pop(0)
; that way the user can still pass a literal"--"
as an argument by doingpython3 known.py -a -- --
, for example so you can pass it along to a wrapped command. β Jarrettjarrid