Support git-style "--" argument behaviour #77
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Giacomo,
I needed to use commandline in a plugin-like scenario, but where I only wanted arguments to be interpreted at the start of the command line, up to the first non-option argument. In my case, we have a command line utility which roughly speaking represents a flexibly-structured pipeline of files and some command tokens (# in the example). There may be some global options, and each command token might have its own options too, which could quite possibly have the same names as the global options. For example:
myapp -v5 file1 # -v3 file2
So I need to:
My options class:
By default, commandline will consider -v5 and -v3 as global options. By setting ParserSettings.DoNotInterpretAfterFirstNonOption to true, the parser stops trying to interpret options when it sees file1, and puts file1 and all subsequent arguments into RemainingArgs (including the -v3).
If the filename "file1" actually begins with a dash, it could be a problem, for example:
myapp -v5 -filename_starting_with_dash # -v3 file2
Many git commands have a workaround for this scenario: the double dash argument. The equivalent behaviour can be enabled by setting ParserSettings.EnableDashDash to true, and using:
myapp -v5 -- -filename_starting_with_dash # -v3 file2
I hope you'll see the usefulness of these changes and consider pulling them.
Many thanks,
Tom Glastonbury