-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserving order between separate options (e.g., --include
and `--exclude)
#761
Comments
Makes sense. I thought that this was already supported in the The API will probably look something like this: (feedback welcome) @Command(name = "rsync")
static class Rsync implements Runnable {
@Option(names = "--include")
List<String> includes;
@Option(names = "--exclude")
List<String> excludes;
@Spec CommandSpec spec;
public void run() {
ParseResult pr = spec.commandLine().getParseResult();
List<ArgSpec> optionSpecs = pr.matchedArgs();
// do something
}
}
@Test
public void testOrderedOptionsWithParseResult() {
CommandLine cmd = new CommandLine(new Rsync());
ParseResult parseResult = cmd.parseArgs("--include", "a", "--exclude", "b", "--include", "c", "--exclude", "d");
List<ArgSpec> argSpecs = parseResult.matchedArgs();
assertEquals(4, argSpecs.size());
assertEquals("--include", ((OptionSpec) argSpecs.get(0)).longestName());
assertEquals("--exclude", ((OptionSpec) argSpecs.get(1)).longestName());
assertEquals("--include", ((OptionSpec) argSpecs.get(2)).longestName());
assertEquals("--exclude", ((OptionSpec) argSpecs.get(3)).longestName());
} |
By that do you mean, |
Correct, I plan to add a And, yes, at the moment I’m thinking that applications can get the values via Note that the current For applications interested in the current behavior I’ll add |
… matched options and positional params * Add `ParseResult.matchedArgs()` method to return all matched arguments in order; * change `ParseResult.matchedOptions()` and `ParseResult.matchedPositionals()` to return the full list of matched options and positional parameters, including duplicates if the option or positional parameter was matched multiple times. * Add new `ParseResult.matchedOptionSet()` and `ParseResult.matchedPositionalSet()` methods that return a `Set`.
This has been implemented and pushed to master. Please verify. |
Is there a way to define
rsync
-style--include
and--exclude
commands where the order of these commands relative to each other is important? Inrsync
the first--include
or--exclude
in the command line that a file matches determines whether the file is included or not.For example, consider
rsync --include=pattern1 --exclude=pattern2 --include=pattern3 --exclude=pattern4
.pattern1
,rsync
includes the file.pattern1
but matchespattern2
,rsync
excludes the file.pattern1
orpattern2
but matchespattern3
,rsync
includes the file.pattern1
,pattern2
orpattern3
but matchespattern4
,rsync
excludes the file.pattern1
,pattern2
,pattern3
orpattern4
,rsync
uses some default handling for the file.If I use a list
@Option
for--include
and a separate list@Option
for--exclude
, the order between includes and the order between excludes is preserved but not the order between includes and excludes.If I use a list
@Option
for both--include
and--exclude
as names, then the order between includes and excludes is preserved, but I don't see a way to know which were includes and which were excludes.The text was updated successfully, but these errors were encountered: