From 8e0796702c32bc4bb5bede0b7bae8a8efd80ca51 Mon Sep 17 00:00:00 2001 From: Remko Popma Date: Sun, 24 May 2020 09:59:44 +0900 Subject: [PATCH] [#10][#732][#1047] DOC update user manual entry for abbreviated options and commands --- docs/index.adoc | 5 +++-- src/test/java/picocli/AbbreviationMatcherTest.java | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/index.adoc b/docs/index.adoc index faa197394..2a261e8dc 100644 --- a/docs/index.adoc +++ b/docs/index.adoc @@ -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. @@ -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); diff --git a/src/test/java/picocli/AbbreviationMatcherTest.java b/src/test/java/picocli/AbbreviationMatcherTest.java index ae7207647..7ae0ba25f 100644 --- a/src/test/java/picocli/AbbreviationMatcherTest.java +++ b/src/test/java/picocli/AbbreviationMatcherTest.java @@ -448,7 +448,7 @@ class App { public boolean b; @Option(names = "-AaaBbb") - public boolean ab; + public boolean aaaBbb; } CommandLine commandLine = new CommandLine(new App()); @@ -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