Skip to content

Commit

Permalink
[#10][#732][#1047] DOC update user manual entry for abbreviated optio…
Browse files Browse the repository at this point in the history
…ns and commands
  • Loading branch information
remkop committed May 24, 2020
1 parent 657678a commit 8e07967
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ Since picocli 4.4, the parser can recognize abbreviated options and subcommands.
This needs to be enabled explicitly with `CommandLine::setAbbreviatedOptionsAllowed` and `CommandLine::setAbbreviatedSubcommandsAllowed`.

==== Recognized Abbreviations
When abbreviations are enabled, users can specify the initial letter(s) of the first component and optionally the initial letter(s) of one or more subsequent components of an option or subcommand name.
When abbreviations are enabled, users can specify the initial letter(s) of the first component and optionally of one or more subsequent components of an option or subcommand name.

"Components" are separated by `-` dash characters or by case, so for example, both `--CamelCase` and `--kebab-case` have two components.

Expand Down Expand Up @@ -2372,7 +2372,8 @@ class AbbreviationsAndPosix {
@Option(names = "-B") boolean b;
@Option(names = "-AaaBbb") boolean aaaBbb;
}
AbbreviationsAndPosix app = CommandLine.populateCommand(new AbbreviationsAndPosix(), "-AB");
AbbreviationsAndPosix app = new AbbreviationsAndPosix();
new CommandLine(app).setAbbreviatedOptionsAllowed(true).parseArgs("-AB");
assertTrue(app.aaaBbb);
assertFalse(app.a);
assertFalse(app.b);
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/picocli/AbbreviationMatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class App {
public boolean b;

@Option(names = "-AaaBbb")
public boolean ab;
public boolean aaaBbb;
}

CommandLine commandLine = new CommandLine(new App());
Expand All @@ -463,6 +463,12 @@ class App {
assertTrue(result.hasMatchedOption("-A"));
assertFalse(result.hasMatchedOption("-B"));
assertFalse(result.hasMatchedOption("-AaaBbb"));

App app = new App();
new CommandLine(app).setAbbreviatedOptionsAllowed(true).parseArgs("-AB");
assertTrue(app.aaaBbb);
assertFalse(app.a);
assertFalse(app.b);
}

@Test
Expand Down

0 comments on commit 8e07967

Please sign in to comment.