Skip to content

Use of `--` to stop parsing arguments as options doesn't work with subcommands

I attempted to use -- to end parsing of options vs. arguments in order to pass arguments that begin with a - (e.g. a negative value), and had unexpected behavior (failures with No such option).

Examples:

# This doesn't work, but is not unexpected
main subcommand -1 -2
# Fails with `No such option "-1"'

# This doesn't work, but would be expected to
main subcommand -- -1 -2
# Fails with `No such option "-1"'

# This works, as a workaround
main subcommand -- -- -1 -2

I assume the nested parsing of the subcommands leads to this behavior. The top-level parsing for the main command grabs the first --, leaving the second-level parsing of the subcommand to then fail on the -1. The use of two -- works, but it would be nice if the top-level parsing of -- could keep the argument on the list when parsing subcommand options.

I just encountered this, and if I find a solution, I'll try to push an MR.