All arguments following "--" in argparse are treated as positional arguments.
e.g.
compgen -W "foo bar baz" -- b
As far as I can tell shtab doesn't treat double dash in a special manner.
It would be pretty nice if shtab recognized this as delimiter between the options and the positional arguments.
I couldn't find a reference to this behavior in argparse documentation, but it's evident from code & usage.
for i, arg_string in enumerate(arg_strings_iter):
# all args after -- are non-options
if arg_string == '--':
...
This is a common practice, as can be seen in POSIX:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the ‘-’ character.
it solves some ambiguity when using optional arguments that accept multiple values.
git checkout master # Checkout the master branch
git checkout -- master # Checkout the file named master
rm -- -file.txt # delete file with dash in name
By taking double dash into account, cases such as above would be completed correctly.
All arguments following "--" in argparse are treated as positional arguments. e.g.
As far as I can tell shtab doesn't treat double dash in a special manner. It would be pretty nice if shtab recognized this as delimiter between the options and the positional arguments.
I couldn't find a reference to this behavior in argparse documentation, but it's evident from code & usage.
This is a common practice, as can be seen in POSIX:
it solves some ambiguity when using optional arguments that accept multiple values.
By taking double dash into account, cases such as above would be completed correctly.