mirror of
https://github.com/jlengrand/picocli.git
synced 2026-03-10 08:41:17 +00:00
@@ -130,6 +130,7 @@ class ExecParameterConsumer implements IParameterConsumer {
|
||||
- [#718] API: Add `IParameterConsumer` and `@Option(parameterConsumer = Xxx.class)` for passing arguments through to another command, like `find -exec`. Thanks to [Reinhard Pointner](https://github.com/rednoah) for the suggestion.
|
||||
- [#721] API: Add public method Text.getCJKAdjustedLength().
|
||||
- [#634] API: Dynamically detect terminal size. Requires Java 7. Thanks to my colleague Takuya Ishibashi for the suggestion.
|
||||
- [#737] Deprecate the `parse` method in favor of `parseArgs`.
|
||||
- [#717] Negatable options change: avoid unmappable character `±` for synopsis: it renders as scrambled characters in encoding ASCII and in some terminals.
|
||||
- [#734][#735] Make the picocli jar OSGi friendly. Thanks to [Radu Cotescu](https://github.com/raducotescu) for the pull request.
|
||||
- [#719] Bugfix: options with variable arity should stop consuming arguments on custom end-of-options delimiter.
|
||||
@@ -141,7 +142,7 @@ class ExecParameterConsumer implements IParameterConsumer {
|
||||
|
||||
|
||||
## <a name="4.0.0-beta-2-deprecated"></a> Deprecations
|
||||
|
||||
From this release, the `parse` method is deprecated in favor of `parseArgs`.
|
||||
|
||||
## <a name="4.0.0-beta-2-breaking-changes"></a> Potential breaking changes
|
||||
|
||||
|
||||
@@ -192,6 +192,7 @@ abstract public class PicocliBaseScript extends Script {
|
||||
* @param args The argument array.
|
||||
* @return the list of {@code CommandLine} objects that result from parsing the user input
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public List<CommandLine> parseScriptArguments(CommandLine commandLine, String[] args) {
|
||||
return commandLine.parse(args);
|
||||
}
|
||||
|
||||
@@ -1132,10 +1132,13 @@ public class CommandLine {
|
||||
* </p><p>
|
||||
* This is equivalent to
|
||||
* </p><pre>
|
||||
* CommandLine cli = new CommandLine(command);
|
||||
* cli.parse(args);
|
||||
* new CommandLine(command).parseArgs(args);
|
||||
* return command;
|
||||
* </pre>
|
||||
* <p>All this method does is parse the arguments and populate the annotated fields and methods.
|
||||
* The caller is responsible for catching any exceptions, handling requests for usage help
|
||||
* or version information, and invoking the business logic.
|
||||
* Applications may be interested in using the {@link #execute(String...)} method instead.</p>
|
||||
*
|
||||
* @param command the object to initialize. This object contains fields annotated with
|
||||
* {@code @Option} or {@code @Parameters}.
|
||||
@@ -1144,6 +1147,7 @@ public class CommandLine {
|
||||
* @return the specified annotated object
|
||||
* @throws InitializationException if the specified command object does not have a {@link Command}, {@link Option} or {@link Parameters} annotation
|
||||
* @throws ParameterException if the specified command line arguments are invalid
|
||||
* @see #execute(String...)
|
||||
* @since 0.9.7
|
||||
*/
|
||||
public static <T> T populateCommand(T command, String... args) {
|
||||
@@ -1164,6 +1168,10 @@ public class CommandLine {
|
||||
* cli.parse(args);
|
||||
* return cli.getCommand();
|
||||
* </pre>
|
||||
* <p>All this method does is parse the arguments and return an instance whose annotated methods return the specified values.
|
||||
* The caller is responsible for catching any exceptions, handling requests for usage help
|
||||
* or version information, and invoking the business logic.
|
||||
* Applications may be interested in using the {@link #execute(String...)} method instead.</p>
|
||||
*
|
||||
* @param spec the interface that defines the command specification. This object contains getter methods annotated with
|
||||
* {@code @Option} or {@code @Parameters}.
|
||||
@@ -1172,6 +1180,7 @@ public class CommandLine {
|
||||
* @return an instance of the specified annotated interface
|
||||
* @throws InitializationException if the specified command object does not have a {@link Command}, {@link Option} or {@link Parameters} annotation
|
||||
* @throws ParameterException if the specified command line arguments are invalid
|
||||
* @see #execute(String...)
|
||||
* @since 3.1
|
||||
*/
|
||||
public static <T> T populateSpec(Class<T> spec, String... args) {
|
||||
@@ -1188,23 +1197,33 @@ public class CommandLine {
|
||||
* and these subcommands were initialized by matching command line arguments. If parsing fails, a
|
||||
* {@link ParameterException} is thrown.
|
||||
* </p>
|
||||
* <p>All this method does is parse the arguments and populate the annotated fields and methods.
|
||||
* The caller is responsible for catching any exceptions, handling requests for usage help
|
||||
* or version information, and invoking the business logic.
|
||||
* Applications may be interested in using the {@link #execute(String...)} method instead.</p>
|
||||
*
|
||||
* @param args the command line arguments to parse
|
||||
* @return a list with the top-level command and any subcommands initialized by this method
|
||||
* @throws ParameterException if the specified command line arguments are invalid; use
|
||||
* {@link ParameterException#getCommandLine()} to get the command or subcommand whose user input was invalid
|
||||
* @deprecated use {@link #parseArgs(String...)} instead
|
||||
*/
|
||||
public List<CommandLine> parse(String... args) {
|
||||
@Deprecated public List<CommandLine> parse(String... args) {
|
||||
return interpreter.parse(args);
|
||||
}
|
||||
/** Parses the specified command line arguments and returns a list of {@code ParseResult} with the options, positional
|
||||
* parameters, and subcommands (if any) that were recognized and initialized during the parsing process.
|
||||
* <p>If parsing fails, a {@link ParameterException} is thrown.</p>
|
||||
* <p>All this method does is parse the arguments and populate the annotated fields and methods.
|
||||
* The caller is responsible for catching any exceptions, handling requests for usage help
|
||||
* or version information, and invoking the business logic.
|
||||
* Applications may be interested in using the {@link #execute(String...)} method instead.</p>
|
||||
*
|
||||
* @param args the command line arguments to parse
|
||||
* @return a list with the top-level command and any subcommands initialized by this method
|
||||
* @throws ParameterException if the specified command line arguments are invalid; use
|
||||
* {@link ParameterException#getCommandLine()} to get the command or subcommand whose user input was invalid
|
||||
* @see #execute(String...)
|
||||
*/
|
||||
public ParseResult parseArgs(String... args) {
|
||||
interpreter.parse(args);
|
||||
@@ -4343,9 +4362,9 @@ public class CommandLine {
|
||||
/**
|
||||
* Options or positional parameters can be assigned a {@code IParameterConsumer} that implements
|
||||
* custom logic to process the parameters for this option or this position.
|
||||
* When an option or positional parameters with a custom {@code IParameterConsumer} is matched on the
|
||||
* When an option or positional parameter with a custom {@code IParameterConsumer} is matched on the
|
||||
* command line, picocli's internal parser is temporarily suspended, and this object becomes
|
||||
* responsible for consuming and processing as many processing command line arguments as needed.
|
||||
* responsible for consuming and processing as many command line arguments as needed.
|
||||
* <p>This may be useful when passing through parameters to another command.</p>
|
||||
* <p>Example usage:</p>
|
||||
* <pre>
|
||||
|
||||
@@ -362,7 +362,7 @@ public class ArgSplitTest {
|
||||
Map<String, String> parameters;
|
||||
}
|
||||
App app = new App();
|
||||
new CommandLine(app).setTrimQuotes(true).parse(args);
|
||||
new CommandLine(app).setTrimQuotes(true).parseArgs(args);
|
||||
assertEquals(2, app.parameters.size());
|
||||
assertEquals("-Dspring.profiles.active=foo,bar -Dspring.mail.host=smtp.mailtrap.io", app.parameters.get("AppOptions"));
|
||||
assertEquals("", app.parameters.get("OtherOptions"));
|
||||
|
||||
@@ -88,6 +88,8 @@ public class AutoCompleteTest {
|
||||
public static class TopLevel {
|
||||
@Option(names = {"-V", "--version"}, help = true) boolean versionRequested;
|
||||
@Option(names = {"-h", "--help"}, help = true) boolean helpRequested;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void main(String[] args) {
|
||||
CommandLine hierarchy = new CommandLine(new TopLevel())
|
||||
.addSubcommand("sub1", new Sub1())
|
||||
|
||||
@@ -126,7 +126,7 @@ public class CommandLineAnnotatedMethodImplTest {
|
||||
@Test
|
||||
public void testObjectsWithDefaultValues() {
|
||||
CommandLine cmd = new CommandLine(ObjectsWithDefaults.class);
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
ObjectsWithDefaults objects = cmd.getCommand();
|
||||
assertTrue(objects.aBoolean);
|
||||
assertEquals(Byte.valueOf((byte) 123), objects.aByte);
|
||||
@@ -228,7 +228,7 @@ public class CommandLineAnnotatedMethodImplTest {
|
||||
|
||||
CommandLine parser = new CommandLine(new App());
|
||||
try {
|
||||
parser.parse("--jvm", "abc");
|
||||
parser.parseArgs("--jvm", "abc");
|
||||
fail("Expected exception");
|
||||
} catch (ParameterException ex) {
|
||||
assertNotNull(ex.getCause());
|
||||
@@ -247,7 +247,7 @@ public class CommandLineAnnotatedMethodImplTest {
|
||||
|
||||
CommandLine parser = new CommandLine(new App());
|
||||
try {
|
||||
parser.parse("--param", "abc");
|
||||
parser.parseArgs("--param", "abc");
|
||||
fail("Expected exception");
|
||||
} catch (ParameterException ex) {
|
||||
assertNull(ex.getCause());
|
||||
@@ -264,7 +264,7 @@ public class CommandLineAnnotatedMethodImplTest {
|
||||
|
||||
CommandLine parser = new CommandLine(new App());
|
||||
try {
|
||||
parser.parse("--pico", "abc");
|
||||
parser.parseArgs("--pico", "abc");
|
||||
fail("Expected exception");
|
||||
} catch (ParameterException ex) {
|
||||
assertNotNull(ex.getCause());
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
@Test
|
||||
public void testPrimitiveWithoutDefaultValues() {
|
||||
CommandLine cmd = new CommandLine(Primitives.class);
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
Primitives primitives = cmd.getCommand();
|
||||
assertFalse(primitives.aBoolean());
|
||||
assertEquals(0, primitives.aByte());
|
||||
@@ -90,7 +90,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
@Test
|
||||
public void testPrimitivesWithDefaultValues() {
|
||||
CommandLine cmd = new CommandLine(PrimitivesWithDefault.class);
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
PrimitivesWithDefault primitives = cmd.getCommand();
|
||||
assertTrue(primitives.aBoolean());
|
||||
assertEquals(11, primitives.aByte());
|
||||
@@ -104,7 +104,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
@Test
|
||||
public void testPrimitives() {
|
||||
CommandLine cmd = new CommandLine(Primitives.class);
|
||||
cmd.parse("-b -y1 -s2 -i3 -l4 -f5 -d6".split(" "));
|
||||
cmd.parseArgs("-b -y1 -s2 -i3 -l4 -f5 -d6".split(" "));
|
||||
Primitives primitives = cmd.getCommand();
|
||||
assertTrue(primitives.aBoolean());
|
||||
assertEquals(1, primitives.aByte());
|
||||
@@ -194,7 +194,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
@Test
|
||||
public void testObjectsWithoutDefaultValues() {
|
||||
CommandLine cmd = new CommandLine(Objects.class);
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
Objects objects = cmd.getCommand();
|
||||
assertNull(objects.aBoolean());
|
||||
assertNull(objects.aByte());
|
||||
@@ -213,7 +213,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
@Test
|
||||
public void testObjectsWithDefaultValues() {
|
||||
CommandLine cmd = new CommandLine(ObjectsWithDefault.class);
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
ObjectsWithDefault objects = cmd.getCommand();
|
||||
assertTrue(objects.aBoolean());
|
||||
assertEquals(Byte.valueOf((byte) 123), objects.aByte());
|
||||
@@ -236,7 +236,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
@Test
|
||||
public void testObjects() {
|
||||
CommandLine cmd = new CommandLine(Objects.class);
|
||||
cmd.parse("-b -y1 -s2 -i3 -l4 -f5 -d6 -bigint=7 -string abc -list a -list b -map 1=2.0 -set 33 -set 22".split(" "));
|
||||
cmd.parseArgs("-b -y1 -s2 -i3 -l4 -f5 -d6 -bigint=7 -string abc -list a -list b -map 1=2.0 -set 33 -set 22".split(" "));
|
||||
Objects objects = cmd.getCommand();
|
||||
assertTrue(objects.aBoolean());
|
||||
assertEquals(Byte.valueOf((byte) 1), objects.aByte());
|
||||
@@ -284,7 +284,7 @@ public class CommandLineAnnotatedMethodSpecTest {
|
||||
public void testAnnotatedMutableFieldsOnInterfaceAreValid() {
|
||||
try {
|
||||
CommandLine cmd = new CommandLine(InvalidAnnotatedMutableFields.class);
|
||||
cmd.parse("-s a -s b -s c".split(" "));
|
||||
cmd.parseArgs("-s a -s b -s c".split(" "));
|
||||
fail("Expected exception");
|
||||
} catch (InitializationException ok) {
|
||||
assertEquals("Invalid picocli annotation on interface field", ok.getMessage());
|
||||
|
||||
@@ -657,7 +657,7 @@ public class CommandLineArityTest {
|
||||
public void testBooleanOptionsArity0_nShortFormFailsIfAttachedParamNotABooleanWithUnmatchedArgsAllowed() { // ignores varargs
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new BooleanOptionsArity0_nAndParameters()).setUnmatchedArgumentsAllowed(true);
|
||||
cmd.parse("-rv234 -bool".split(" "));
|
||||
cmd.parseArgs("-rv234 -bool".split(" "));
|
||||
assertEquals(Arrays.asList("-234"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
@Test
|
||||
@@ -1405,7 +1405,7 @@ public class CommandLineArityTest {
|
||||
}
|
||||
Cmd cmd = new Cmd();
|
||||
System.setProperty("picocli.trace", "DEBUG");
|
||||
new CommandLine(cmd).setStopAtPositional(true).parse("foo", "xx", "--alpha", "--beta");
|
||||
new CommandLine(cmd).setStopAtPositional(true).parseArgs("foo", "xx", "--alpha", "--beta");
|
||||
assertEquals("foo", cmd.foo);
|
||||
assertEquals(null, cmd.alpha);
|
||||
assertEquals(Arrays.asList("xx", "--alpha", "--beta"), cmd.params);
|
||||
@@ -1420,7 +1420,7 @@ public class CommandLineArityTest {
|
||||
@Parameters(index = "1..*") List<String> params;
|
||||
}
|
||||
Cmd cmd = new Cmd();
|
||||
new CommandLine(cmd).setStopAtPositional(true).parse("foo", "xx", "--alpha", "--beta");
|
||||
new CommandLine(cmd).setStopAtPositional(true).parseArgs("foo", "xx", "--alpha", "--beta");
|
||||
assertEquals("foo", cmd.foo);
|
||||
assertEquals(null, cmd.alpha);
|
||||
assertEquals(Arrays.asList("xx", "--alpha", "--beta"), cmd.params);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class CommandLineDefaultProviderTest {
|
||||
@Test
|
||||
public void testCommandDefaultProviderByAnnotationOverridesValues() {
|
||||
CommandLine cmd = new CommandLine(App.class);
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
|
||||
App app = cmd.getCommand();
|
||||
// if no default defined on the option, command default provider should be used
|
||||
@@ -103,7 +103,7 @@ public class CommandLineDefaultProviderTest {
|
||||
|
||||
cmd.setDefaultValueProvider(new TestNullDefaultProvider());
|
||||
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
|
||||
App app = cmd.getCommand();
|
||||
// if no default defined on the option, command default provider should be used
|
||||
@@ -162,7 +162,7 @@ public class CommandLineDefaultProviderTest {
|
||||
|
||||
CommandLine cmd = new CommandLine(App.class);
|
||||
cmd.setDefaultValueProvider(new TestDefaultProvider());
|
||||
cmd.parse();
|
||||
cmd.parseArgs();
|
||||
|
||||
App app = cmd.getCommand();
|
||||
// if no default defined on the option, command default provider should be used
|
||||
|
||||
@@ -3079,6 +3079,7 @@ public class CommandLineHelpTest {
|
||||
}
|
||||
@Command(name = "sub", description = "This is a subcommand") static class Sub {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void test244SubcommandsNotParsed() {
|
||||
List<CommandLine> list = new CommandLine(new Top()).parse("-h", "sub");
|
||||
|
||||
@@ -609,7 +609,7 @@ public class CommandLineMixinTest {
|
||||
InjectsOptionsAndParameters.MixMeIn mixMeIn;
|
||||
}
|
||||
CommandLine commandLine = new CommandLine(new Receiver());
|
||||
commandLine.parse("-a", "111", "-b", "222", "a", "b");
|
||||
commandLine.parseArgs("-a", "111", "-b", "222", "a", "b");
|
||||
Receiver receiver = commandLine.getCommand();
|
||||
assertEquals(222, receiver.beta);
|
||||
assertEquals(111, receiver.mixMeIn.alpha);
|
||||
@@ -631,7 +631,7 @@ public class CommandLineMixinTest {
|
||||
InjectsOptionsAndParameters.MixMeIn mixin = new InjectsOptionsAndParameters.MixMeIn();
|
||||
commandLine.addMixin("mixin", mixin);
|
||||
|
||||
commandLine.parse("-a", "111", "-b", "222", "a", "b");
|
||||
commandLine.parseArgs("-a", "111", "-b", "222", "a", "b");
|
||||
Receiver receiver = commandLine.getCommand();
|
||||
assertEquals(222, receiver.beta);
|
||||
assertEquals(111, mixin.alpha);
|
||||
@@ -857,13 +857,13 @@ public class CommandLineMixinTest {
|
||||
|
||||
private void assertExceptionThrownFromSetter(CommandLine cmd) {
|
||||
try {
|
||||
cmd.parse("--trex", "abc");
|
||||
cmd.parseArgs("--trex", "abc");
|
||||
fail("expected ParameterException");
|
||||
} catch (ParameterException ex) {
|
||||
assertEquals("TREX error", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
cmd.parse("--raptor", "xyz");
|
||||
cmd.parseArgs("--raptor", "xyz");
|
||||
fail("expected ParameterException");
|
||||
} catch (ParameterException ex) {
|
||||
assertEquals("RAPTOR error", ex.getMessage());
|
||||
|
||||
@@ -59,7 +59,7 @@ public class CommandLineModelTest {
|
||||
CommandSpec spec = CommandSpec.create();
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.setUnmatchedArgumentsAllowed(true);
|
||||
commandLine.parse("-p", "123", "abc");
|
||||
commandLine.parseArgs("-p", "123", "abc");
|
||||
assertEquals(Arrays.asList("-p", "123", "abc"), commandLine.getUnmatchedArguments());
|
||||
}
|
||||
|
||||
@@ -279,10 +279,10 @@ public class CommandLineModelTest {
|
||||
parent.addSubcommand("help", helpCommand);
|
||||
|
||||
CommandLine commandLine = new CommandLine(parent);
|
||||
commandLine.parse("help"); // no missing param exception
|
||||
commandLine.parseArgs("help"); // no missing param exception
|
||||
|
||||
try {
|
||||
commandLine.parse();
|
||||
commandLine.parseArgs();
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required option '-x=PARAM'", ex.getMessage());
|
||||
assertEquals(1, ex.getMissing().size());
|
||||
@@ -297,7 +297,7 @@ public class CommandLineModelTest {
|
||||
spec.addOption(OptionSpec.builder("-V", "--version").versionHelp(true).description("show help and exit").build());
|
||||
spec.addOption(OptionSpec.builder("-c", "--count").paramLabel("COUNT").arity("1").type(int.class).description("number of times to execute").build());
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "33");
|
||||
commandLine.parseArgs("-c", "33");
|
||||
assertEquals(Integer.valueOf(33), spec.optionsMap().get("-c").getValue());
|
||||
} // TODO parse method should return an object offering only the options/positionals that were matched
|
||||
|
||||
@@ -310,7 +310,7 @@ public class CommandLineModelTest {
|
||||
spec.addOption(option);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
try {
|
||||
commandLine.parse("-c", "1", "2", "3");
|
||||
commandLine.parseArgs("-c", "1", "2", "3");
|
||||
fail("Expected exception");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched arguments: 2, 3", ex.getMessage());
|
||||
@@ -326,7 +326,7 @@ public class CommandLineModelTest {
|
||||
spec.addPositional(positional);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
try {
|
||||
commandLine.parse("1", "2", "3");
|
||||
commandLine.parseArgs("1", "2", "3");
|
||||
fail("Expected exception");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched arguments: 2, 3", ex.getMessage());
|
||||
@@ -341,7 +341,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addOption(option);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "1", "2", "3");
|
||||
commandLine.parseArgs("-c", "1", "2", "3");
|
||||
assertArrayEquals(new int[] {1, 2, 3}, (int[]) spec.optionsMap().get("-c").getValue());
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addPositional(positional);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("1", "2", "3");
|
||||
commandLine.parseArgs("1", "2", "3");
|
||||
assertArrayEquals(new int[] {1, 2, 3}, (int[]) spec.positionalParameters().get(0).getValue());
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addOption(option);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "1", "2", "3");
|
||||
commandLine.parseArgs("-c", "1", "2", "3");
|
||||
assertEquals(Arrays.asList(1, 2, 3), spec.optionsMap().get("-c").getValue());
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addPositional(positional);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("1", "2", "3");
|
||||
commandLine.parseArgs("1", "2", "3");
|
||||
assertEquals(Arrays.asList(1, 2, 3), spec.positionalParameters().get(0).getValue());
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addOption(option);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "1", "2", "3");
|
||||
commandLine.parseArgs("-c", "1", "2", "3");
|
||||
assertEquals(Arrays.asList("1", "2", "3"), spec.optionsMap().get("-c").getValue());
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addPositional(positional);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("1", "2", "3");
|
||||
commandLine.parseArgs("1", "2", "3");
|
||||
assertEquals(Arrays.asList("1", "2", "3"), spec.positionalParameters().get(0).getValue());
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addOption(option);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "1=1.0", "2=2.0", "3=3.0");
|
||||
commandLine.parseArgs("-c", "1=1.0", "2=2.0", "3=3.0");
|
||||
Map<Integer, Double> expected = new LinkedHashMap<Integer, Double>();
|
||||
expected.put(1, 1.0);
|
||||
expected.put(2, 2.0);
|
||||
@@ -429,7 +429,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addPositional(positional);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("1=1.0", "2=2.0", "3=3.0");
|
||||
commandLine.parseArgs("1=1.0", "2=2.0", "3=3.0");
|
||||
Map<Integer, Double> expected = new LinkedHashMap<Integer, Double>();
|
||||
expected.put(1, 1.0);
|
||||
expected.put(2, 2.0);
|
||||
@@ -445,7 +445,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addOption(option);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "1=1.0", "2=2.0", "3=3.0");
|
||||
commandLine.parseArgs("-c", "1=1.0", "2=2.0", "3=3.0");
|
||||
Map<String, String> expected = new LinkedHashMap<String, String>();
|
||||
expected.put("1", "1.0");
|
||||
expected.put("2", "2.0");
|
||||
@@ -461,7 +461,7 @@ public class CommandLineModelTest {
|
||||
|
||||
spec.addPositional(positional);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("1=1.0", "2=2.0", "3=3.0");
|
||||
commandLine.parseArgs("1=1.0", "2=2.0", "3=3.0");
|
||||
Map<String, String> expected = new LinkedHashMap<String, String>();
|
||||
expected.put("1", "1.0");
|
||||
expected.put("2", "2.0");
|
||||
@@ -476,7 +476,7 @@ public class CommandLineModelTest {
|
||||
spec.addOption(OptionSpec.builder("-s", "--sql").paramLabel("SQLTYPE").type(int.class).converters(
|
||||
new CommandLineTypeConversionTest.SqlTypeConverter()).description("sql type converter").build());
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "33", "-s", "BLOB");
|
||||
commandLine.parseArgs("-c", "33", "-s", "BLOB");
|
||||
assertEquals(Integer.valueOf(33), spec.optionsMap().get("-c").getValue());
|
||||
assertEquals(Integer.valueOf(Types.BLOB), spec.optionsMap().get("-s").getValue());
|
||||
}
|
||||
@@ -487,7 +487,7 @@ public class CommandLineModelTest {
|
||||
spec.addPositional(PositionalParamSpec.builder().paramLabel("SQLTYPE").index("1").type(int.class).converters(
|
||||
new CommandLineTypeConversionTest.SqlTypeConverter()).description("sql type converter").build());
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("33", "BLOB");
|
||||
commandLine.parseArgs("33", "BLOB");
|
||||
assertEquals(Integer.valueOf(33), spec.positionalParameters().get(0).getValue());
|
||||
assertEquals(Integer.valueOf(Types.BLOB), spec.positionalParameters().get(1).getValue());
|
||||
}
|
||||
@@ -520,6 +520,7 @@ public class CommandLineModelTest {
|
||||
}
|
||||
|
||||
/** see <a href="https://github.com/remkop/picocli/issues/279">issue #279</a> */
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testSingleValueFieldWithOptionalParameter_279() {
|
||||
@Command(name="sample")
|
||||
@@ -546,6 +547,7 @@ public class CommandLineModelTest {
|
||||
}
|
||||
|
||||
/** see <a href="https://github.com/remkop/picocli/issues/280">issue #280</a> */
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testSingleValueFieldWithOptionalParameter_280() {
|
||||
@Command(name="sample")
|
||||
@@ -572,6 +574,7 @@ public class CommandLineModelTest {
|
||||
}
|
||||
|
||||
/** see <a href="https://github.com/remkop/picocli/issues/279">issue #279</a> */
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testSingleValueFieldWithOptionalParameterFollowedByOption_279() {
|
||||
@Command(name="sample")
|
||||
@@ -591,6 +594,7 @@ public class CommandLineModelTest {
|
||||
}
|
||||
|
||||
/** see <a href="https://github.com/remkop/picocli/issues/280">issue #280</a> */
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testSingleValueFieldWithOptionalParameterFollowedByOption_280() {
|
||||
@Command(name="sample")
|
||||
|
||||
@@ -157,7 +157,7 @@ public class CommandLineTest {
|
||||
ArrayPositionalParams params = new ArrayPositionalParams();
|
||||
params.array = new int[3];
|
||||
int[] array = params.array;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotSame(array, params.array);
|
||||
assertArrayEquals(new int[]{3, 2, 1}, params.array);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public class CommandLineTest {
|
||||
}
|
||||
}
|
||||
ArrayPositionalParams params = new ArrayPositionalParams();
|
||||
new CommandLine(params).parse("foo", "bar", "baz");
|
||||
new CommandLine(params).parseArgs("foo", "bar", "baz");
|
||||
assertEquals("foobarbaz", params.string);
|
||||
}
|
||||
@Test
|
||||
@@ -190,7 +190,7 @@ public class CommandLineTest {
|
||||
}
|
||||
}
|
||||
ArrayPositionalParams params = new ArrayPositionalParams();
|
||||
new CommandLine(params).parse("-s", "foo", "-s", "bar", "-s", "baz");
|
||||
new CommandLine(params).parseArgs("-s", "foo", "-s", "bar", "-s", "baz");
|
||||
assertEquals("foobarbaz", params.string);
|
||||
}
|
||||
private class ListPositionalParams {
|
||||
@@ -200,7 +200,7 @@ public class CommandLineTest {
|
||||
public void testListPositionalParametersAreInstantiatedIfNull() {
|
||||
ListPositionalParams params = new ListPositionalParams();
|
||||
assertNull(params.list);
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotNull(params.list);
|
||||
assertEquals(Arrays.asList(3, 2, 1), params.list);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public class CommandLineTest {
|
||||
ListPositionalParams params = new ListPositionalParams();
|
||||
params.list = new ArrayList<Integer>();
|
||||
List<Integer> list = params.list;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertSame(list, params.list);
|
||||
assertEquals(Arrays.asList(3, 2, 1), params.list);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ public class CommandLineTest {
|
||||
params.list = new ArrayList<Integer>();
|
||||
params.list.add(234);
|
||||
List<Integer> list = params.list;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotSame(list, params.list);
|
||||
assertEquals(Arrays.asList(3, 2, 1), params.list);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public class CommandLineTest {
|
||||
public void testSortedSetPositionalParametersAreInstantiatedIfNull() {
|
||||
SortedSetPositionalParams params = new SortedSetPositionalParams();
|
||||
assertNull(params.sortedSet);
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotNull(params.sortedSet);
|
||||
assertEquals(Arrays.asList(1, 2, 3), new ArrayList<Integer>(params.sortedSet));
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class CommandLineTest {
|
||||
SortedSetPositionalParams params = new SortedSetPositionalParams();
|
||||
params.sortedSet = new TreeSet<Integer>();
|
||||
SortedSet<Integer> list = params.sortedSet;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertSame(list, params.sortedSet);
|
||||
assertEquals(Arrays.asList(1, 2, 3), new ArrayList<Integer>(params.sortedSet));
|
||||
}
|
||||
@@ -249,7 +249,7 @@ public class CommandLineTest {
|
||||
params.sortedSet = new TreeSet<Integer>();
|
||||
params.sortedSet.add(234);
|
||||
SortedSet<Integer> list = params.sortedSet;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotSame(list, params.sortedSet);
|
||||
assertEquals(Arrays.asList(1, 2, 3), new ArrayList<Integer>(params.sortedSet));
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public class CommandLineTest {
|
||||
public void testSetPositionalParametersAreInstantiatedIfNull() {
|
||||
SetPositionalParams params = new SetPositionalParams();
|
||||
assertNull(params.set);
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotNull(params.set);
|
||||
assertEquals(new HashSet<Integer>(Arrays.asList(1, 2, 3)), params.set);
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public class CommandLineTest {
|
||||
SetPositionalParams params = new SetPositionalParams();
|
||||
params.set = new TreeSet<Integer>();
|
||||
Set<Integer> list = params.set;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertSame(list, params.set);
|
||||
assertEquals(new HashSet<Integer>(Arrays.asList(1, 2, 3)), params.set);
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public class CommandLineTest {
|
||||
params.set = new TreeSet<Integer>();
|
||||
params.set.add(234);
|
||||
Set<Integer> list = params.set;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotSame(list, params.set);
|
||||
assertEquals(new HashSet<Integer>(Arrays.asList(3, 2, 1)), params.set);
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class CommandLineTest {
|
||||
public void testQueuePositionalParametersAreInstantiatedIfNull() {
|
||||
QueuePositionalParams params = new QueuePositionalParams();
|
||||
assertNull(params.queue);
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotNull(params.queue);
|
||||
assertEquals(new LinkedList<Integer>(Arrays.asList(3, 2, 1)), params.queue);
|
||||
}
|
||||
@@ -299,7 +299,7 @@ public class CommandLineTest {
|
||||
QueuePositionalParams params = new QueuePositionalParams();
|
||||
params.queue = new LinkedList<Integer>();
|
||||
Queue<Integer> list = params.queue;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertSame(list, params.queue);
|
||||
assertEquals(new LinkedList<Integer>(Arrays.asList(3, 2, 1)), params.queue);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ public class CommandLineTest {
|
||||
params.queue = new LinkedList<Integer>();
|
||||
params.queue.add(234);
|
||||
Queue<Integer> list = params.queue;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotSame(list, params.queue);
|
||||
assertEquals(new LinkedList<Integer>(Arrays.asList(3, 2, 1)), params.queue);
|
||||
}
|
||||
@@ -320,7 +320,7 @@ public class CommandLineTest {
|
||||
public void testCollectionPositionalParametersAreInstantiatedIfNull() {
|
||||
CollectionPositionalParams params = new CollectionPositionalParams();
|
||||
assertNull(params.collection);
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotNull(params.collection);
|
||||
assertEquals(Arrays.asList(3, 2, 1), params.collection);
|
||||
}
|
||||
@@ -329,7 +329,7 @@ public class CommandLineTest {
|
||||
CollectionPositionalParams params = new CollectionPositionalParams();
|
||||
params.collection = new ArrayList<Integer>();
|
||||
Collection<Integer> list = params.collection;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertSame(list, params.collection);
|
||||
assertEquals(Arrays.asList(3, 2, 1), params.collection);
|
||||
}
|
||||
@@ -339,7 +339,7 @@ public class CommandLineTest {
|
||||
params.collection = new ArrayList<Integer>();
|
||||
params.collection.add(234);
|
||||
Collection<Integer> list = params.collection;
|
||||
new CommandLine(params).parse("3", "2", "1");
|
||||
new CommandLine(params).parseArgs("3", "2", "1");
|
||||
assertNotSame(list, params.collection);
|
||||
assertEquals(Arrays.asList(3, 2, 1), params.collection);
|
||||
}
|
||||
@@ -384,7 +384,7 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new App()).setOverwrittenOptionsAllowed(true);
|
||||
cmd.parse("-f", "111", "-f", "222");
|
||||
cmd.parseArgs("-f", "111", "-f", "222");
|
||||
App ff = cmd.getCommand();
|
||||
assertEquals("222", ff.field);
|
||||
}
|
||||
@@ -411,7 +411,7 @@ public class CommandLineTest {
|
||||
@Test
|
||||
public void testPrivateFinalNonPrimitiveNonStringFieldsAreAllowed() throws Exception {
|
||||
PrivateFinalAllowedFields fields = new PrivateFinalAllowedFields();
|
||||
new CommandLine(fields).parse("-d=2017-11-02", "-u=MILLISECONDS", "123", "123456");
|
||||
new CommandLine(fields).parseArgs("-d=2017-11-02", "-u=MILLISECONDS", "123", "123456");
|
||||
assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-02"), fields.date);
|
||||
assertSame(TimeUnit.MILLISECONDS, fields.enumValue);
|
||||
assertEquals(Integer.valueOf(123), fields.integer);
|
||||
@@ -428,7 +428,7 @@ public class CommandLineTest {
|
||||
assertFalse(cmd.isCaseInsensitiveEnumValuesAllowed());
|
||||
|
||||
try {
|
||||
cmd.parse("-u=milliseconds");
|
||||
cmd.parseArgs("-u=milliseconds");
|
||||
fail("Expected exception");
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getMessage(), ex.getMessage().startsWith("Invalid value for option '-u': expected one of "));
|
||||
@@ -437,7 +437,7 @@ public class CommandLineTest {
|
||||
@Test
|
||||
public void testParserCaseInsensitiveEnumValuesAllowed_enabled() throws Exception {
|
||||
PojoWithEnumOptions fields = new PojoWithEnumOptions();
|
||||
new CommandLine(fields).setCaseInsensitiveEnumValuesAllowed(true).parse("-u=milliseconds");
|
||||
new CommandLine(fields).setCaseInsensitiveEnumValuesAllowed(true).parseArgs("-u=milliseconds");
|
||||
assertSame(TimeUnit.MILLISECONDS, fields.enumValue);
|
||||
}
|
||||
@Test
|
||||
@@ -446,7 +446,7 @@ public class CommandLineTest {
|
||||
CommandLine cmd = new CommandLine(fields).setCaseInsensitiveEnumValuesAllowed(true);
|
||||
|
||||
try {
|
||||
cmd.parse("-u=millisecondINVALID");
|
||||
cmd.parseArgs("-u=millisecondINVALID");
|
||||
fail("Expected exception");
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getMessage(), ex.getMessage().startsWith("Invalid value for option '-u': expected one of "));
|
||||
@@ -488,21 +488,25 @@ public class CommandLineTest {
|
||||
RequiredField requiredField = CommandLine.populateCommand(new RequiredField(), "--version");
|
||||
assertTrue("version info requested", requiredField.versionHelp);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testCommandLine_isUsageHelpRequested_trueWhenSpecified() {
|
||||
List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--help");
|
||||
assertTrue("usage help requested", parsedCommands.get(0).isUsageHelpRequested());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testCommandLine_isVersionHelpRequested_trueWhenSpecified() {
|
||||
List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--version");
|
||||
assertTrue("version info requested", parsedCommands.get(0).isVersionHelpRequested());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testCommandLine_isUsageHelpRequested_falseWhenNotSpecified() {
|
||||
List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--version");
|
||||
assertFalse("usage help requested", parsedCommands.get(0).isUsageHelpRequested());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testCommandLine_isVersionHelpRequested_falseWhenNotSpecified() {
|
||||
List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--help");
|
||||
@@ -527,14 +531,14 @@ public class CommandLineTest {
|
||||
public void testHelpRequestedFlagResetWhenParsing_instanceMethod() {
|
||||
RequiredField requiredField = new RequiredField();
|
||||
CommandLine commandLine = new CommandLine(requiredField);
|
||||
commandLine.parse("-?");
|
||||
commandLine.parseArgs("-?");
|
||||
assertTrue("help requested", requiredField.isHelpRequested);
|
||||
|
||||
requiredField.isHelpRequested = false;
|
||||
|
||||
// should throw error again on second pass (no help was requested here...)
|
||||
try {
|
||||
commandLine.parse("arg1", "arg2");
|
||||
commandLine.parseArgs("arg1", "arg2");
|
||||
fail("Missing required field should have thrown exception");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required option '--required=<required>'", ex.getMessage());
|
||||
@@ -598,7 +602,7 @@ public class CommandLineTest {
|
||||
public void testCompactFieldsWithUnmatchedArguments() {
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new CompactFields()).setUnmatchedArgumentsAllowed(true);
|
||||
cmd.parse("-oout -r -vp1 p2".split(" "));
|
||||
cmd.parseArgs("-oout -r -vp1 p2".split(" "));
|
||||
assertEquals(Arrays.asList("-p1"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
|
||||
@@ -619,7 +623,7 @@ public class CommandLineTest {
|
||||
CompactFields compact = new CompactFields();
|
||||
CommandLine cmd = new CommandLine(compact);
|
||||
cmd.setSeparator(":");
|
||||
cmd.parse("-rvo:out p1 p2".split(" "));
|
||||
cmd.parseArgs("-rvo:out p1 p2".split(" "));
|
||||
verifyCompact(compact, true, true, "out", fileArray("p1", "p2"));
|
||||
}
|
||||
|
||||
@@ -702,7 +706,7 @@ public class CommandLineTest {
|
||||
CompactFields compact = new CompactFields();
|
||||
CommandLine cmd = new CommandLine(compact);
|
||||
cmd.setSeparator(":");
|
||||
cmd.parse("-ro: -v".split(" "));
|
||||
cmd.parseArgs("-ro: -v".split(" "));
|
||||
verifyCompact(compact, false, true, "-v", null);
|
||||
}
|
||||
@Test
|
||||
@@ -724,7 +728,7 @@ public class CommandLineTest {
|
||||
CompactFields compact = new CompactFields();
|
||||
CommandLine cmd = new CommandLine(compact);
|
||||
cmd.setSeparator(":");
|
||||
cmd.parse("-ro:\"\" -v".split(" "));
|
||||
cmd.parseArgs("-ro:\"\" -v".split(" "));
|
||||
verifyCompact(compact, true, true, "\"\"", null);
|
||||
}
|
||||
@Test
|
||||
@@ -740,7 +744,7 @@ public class CommandLineTest {
|
||||
CommandLine cmd = new CommandLine(new CompactFields());
|
||||
cmd.getCommandSpec().parser().posixClusteredShortOptionsAllowed(false);
|
||||
try {
|
||||
cmd.parse("-rvoFILE");
|
||||
cmd.parseArgs("-rvoFILE");
|
||||
fail("Expected exception");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unknown option: -rvoFILE", ex.getMessage());
|
||||
@@ -756,7 +760,7 @@ public class CommandLineTest {
|
||||
CommandLine cmd = new CommandLine(unclustered);
|
||||
cmd.getCommandSpec().parser().posixClusteredShortOptionsAllowed(false);
|
||||
try {
|
||||
cmd.parse(args);
|
||||
cmd.parseArgs(args);
|
||||
fail("Expected exception");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unknown option: -oFILE", ex.getMessage());
|
||||
@@ -771,7 +775,7 @@ public class CommandLineTest {
|
||||
CompactFields unclustered = new CompactFields();
|
||||
CommandLine cmd = new CommandLine(unclustered);
|
||||
cmd.getCommandSpec().parser().posixClusteredShortOptionsAllowed(false);
|
||||
cmd.parse(args);
|
||||
cmd.parseArgs(args);
|
||||
verifyCompact(unclustered, true, true, "FILE", null);
|
||||
}
|
||||
|
||||
@@ -786,7 +790,7 @@ public class CommandLineTest {
|
||||
CompactFields compact = new CompactFields();
|
||||
CommandLine cmd = new CommandLine(compact);
|
||||
cmd.setEndOfOptionsDelimiter(";;");
|
||||
cmd.parse("-oout ;; ;; -- -r -v p1 p2".split(" "));
|
||||
cmd.parseArgs("-oout ;; ;; -- -r -v p1 p2".split(" "));
|
||||
verifyCompact(compact, false, false, "out", fileArray(";;", "--","-r", "-v", "p1", "p2"));
|
||||
}
|
||||
|
||||
@@ -1047,13 +1051,13 @@ public class CommandLineTest {
|
||||
params = new VariousPrefixCharacters();
|
||||
CommandLine cmd = new CommandLine(params);
|
||||
cmd.setSeparator(":");
|
||||
cmd.parse("--dash:345");
|
||||
cmd.parseArgs("--dash:345");
|
||||
assertEquals("--dash:val", 345, params.dash);
|
||||
|
||||
params = new VariousPrefixCharacters();
|
||||
cmd = new CommandLine(params);
|
||||
cmd.setSeparator(":");
|
||||
cmd.parse("--dash:345 --owner:y".split(" "));
|
||||
cmd.parseArgs("--dash:345 --owner:y".split(" "));
|
||||
assertEquals("--dash:val", 345, params.dash);
|
||||
assertEquals("--owner:y", "y", params.owner);
|
||||
}
|
||||
@@ -1092,7 +1096,7 @@ public class CommandLineTest {
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new App()).setUnmatchedArgumentsAllowed(true);
|
||||
try {
|
||||
cmd.parse("--opt=abc");
|
||||
cmd.parseArgs("--opt=abc");
|
||||
fail("Expected MissingParameterException");
|
||||
} catch (MissingParameterException ok) {
|
||||
assertEquals("Missing required option '--opt:<opt>'", ok.getMessage());
|
||||
@@ -1142,7 +1146,7 @@ public class CommandLineTest {
|
||||
VariousPrefixCharacters params = new VariousPrefixCharacters();
|
||||
CommandLine cmd = new CommandLine(params);
|
||||
cmd.setSeparator(":");
|
||||
cmd.parse("-d 123 /4 /S 765 /T:98 /Owner:xyz -SingleDash [CPM CP/M (CMS:cmsVal".split(" "));
|
||||
cmd.parseArgs("-d 123 /4 /S 765 /T:98 /Owner:xyz -SingleDash [CPM CP/M (CMS:cmsVal".split(" "));
|
||||
assertEquals("-d", 123, params.dash);
|
||||
assertEquals("/S", 765, params.slashS);
|
||||
assertEquals("/T", 98, params.slashT);
|
||||
@@ -1432,7 +1436,7 @@ public class CommandLineTest {
|
||||
@Parameters List<String> all;
|
||||
}
|
||||
App app1 = new App();
|
||||
new CommandLine(app1).setOverwrittenOptionsAllowed(true).parse("000", "111", "222", "333");
|
||||
new CommandLine(app1).setOverwrittenOptionsAllowed(true).parseArgs("000", "111", "222", "333");
|
||||
assertEquals("field initialized with arg[0]", new File("111"), app1.file0_1);
|
||||
assertEquals("arg[1] and arg[2]", Arrays.asList(
|
||||
new File("111"),
|
||||
@@ -1446,7 +1450,7 @@ public class CommandLineTest {
|
||||
assertEquals("args", Arrays.asList("000", "111", "222", "333"), app1.all);
|
||||
|
||||
App app2 = new App();
|
||||
new CommandLine(app2).setOverwrittenOptionsAllowed(true).parse("000", "111");
|
||||
new CommandLine(app2).setOverwrittenOptionsAllowed(true).parseArgs("000", "111");
|
||||
assertEquals("field initialized with arg[0]", new File("111"), app2.file0_1);
|
||||
assertEquals("arg[1]", Arrays.asList(new File("111")), app2.fileList1_2);
|
||||
assertArrayEquals("arg[0-3]", new File[]{
|
||||
@@ -1620,7 +1624,7 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new SingleValue()).setUnmatchedArgumentsAllowed(true);
|
||||
cmd.parse("val1", "val2");
|
||||
cmd.parseArgs("val1", "val2");
|
||||
assertEquals("val1", ((SingleValue)cmd.getCommand()).str);
|
||||
assertEquals(Arrays.asList("val2"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
@@ -1632,7 +1636,7 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new SingleValue()).setUnmatchedArgumentsAllowed(true);
|
||||
cmd.parse("val0", "val1", "val2", "val3");
|
||||
cmd.parseArgs("val0", "val1", "val2", "val3");
|
||||
assertArrayEquals(new String[]{"val0", "val1", "val2"}, ((SingleValue)cmd.getCommand()).str);
|
||||
assertEquals(Arrays.asList("val3"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
@@ -1663,10 +1667,11 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new SingleValue()).setOverwrittenOptionsAllowed(true);
|
||||
cmd.parse("val1", "val2");
|
||||
cmd.parseArgs("val1", "val2");
|
||||
assertEquals("val2", ((SingleValue) cmd.getCommand()).str);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParseSubCommands() {
|
||||
CommandLine commandLine = Demo.mainCommand();
|
||||
@@ -1695,7 +1700,7 @@ public class CommandLineTest {
|
||||
String old = System.getProperty(PROPERTY);
|
||||
System.setProperty(PROPERTY, "");
|
||||
CommandLine commandLine = Demo.mainCommand();
|
||||
commandLine.parse("--git-dir=/home/rpopma/picocli", "commit", "-m", "\"Fixed typos\"", "--", "src1.java", "src2.java", "src3.java");
|
||||
commandLine.parseArgs("--git-dir=/home/rpopma/picocli", "commit", "-m", "\"Fixed typos\"", "--", "src1.java", "src2.java", "src3.java");
|
||||
System.setErr(originalErr);
|
||||
if (old == null) {
|
||||
System.clearProperty(PROPERTY);
|
||||
@@ -1727,7 +1732,7 @@ public class CommandLineTest {
|
||||
String old = System.getProperty(PROPERTY);
|
||||
System.setProperty(PROPERTY, "DEBUG");
|
||||
CommandLine commandLine = Demo.mainCommand();
|
||||
commandLine.parse("--git-dir=/home/rpopma/picocli", "commit", "-m", "\"Fixed typos\"", "--", "src1.java", "src2.java", "src3.java");
|
||||
commandLine.parseArgs("--git-dir=/home/rpopma/picocli", "commit", "-m", "\"Fixed typos\"", "--", "src1.java", "src2.java", "src3.java");
|
||||
System.setErr(originalErr);
|
||||
if (old == null) {
|
||||
System.clearProperty(PROPERTY);
|
||||
@@ -1857,7 +1862,7 @@ public class CommandLineTest {
|
||||
@Option(names = "-p") int primitive = 43;
|
||||
}
|
||||
CommandLine cmd = new CommandLine(new App()).setOverwrittenOptionsAllowed(true);
|
||||
cmd.parse("-f", "111", "-f", "222", "-f", "333");
|
||||
cmd.parseArgs("-f", "111", "-f", "222", "-f", "333");
|
||||
App ff = cmd.getCommand();
|
||||
assertEquals("333", ff.field);
|
||||
System.setErr(originalErr);
|
||||
@@ -1874,6 +1879,7 @@ public class CommandLineTest {
|
||||
assertEquals(expected, actual);
|
||||
setTraceLevel("WARN");
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTraceWarningIfUnmatchedArgsWhenUnmatchedArgumentsAllowed() throws Exception {
|
||||
PrintStream originalErr = System.err;
|
||||
@@ -2016,11 +2022,11 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine commandLine = new CommandLine(new App()).setOverwrittenOptionsAllowed(true);
|
||||
commandLine.parse("-s", "1", "--str", "2");
|
||||
commandLine.parseArgs("-s", "1", "--str", "2");
|
||||
assertEquals("2", ((App) commandLine.getCommand()).string);
|
||||
|
||||
commandLine = new CommandLine(new App()).setOverwrittenOptionsAllowed(true);
|
||||
commandLine.parse("-v", "--verbose", "-v"); // F -> T -> F -> T
|
||||
commandLine.parseArgs("-v", "--verbose", "-v"); // F -> T -> F -> T
|
||||
assertEquals(true, ((App) commandLine.getCommand()).bool);
|
||||
}
|
||||
|
||||
@@ -2039,7 +2045,7 @@ public class CommandLineTest {
|
||||
CommandLine commandLine = new CommandLine(new App())
|
||||
.addSubcommand("parent", new Parent())
|
||||
.setOverwrittenOptionsAllowed(true);
|
||||
commandLine.parse("-s", "1", "--str", "2", "parent", "--parent", "parentVal", "--parent", "2ndVal");
|
||||
commandLine.parseArgs("-s", "1", "--str", "2", "parent", "--parent", "parentVal", "--parent", "2ndVal");
|
||||
|
||||
App app = commandLine.getCommand();
|
||||
assertEquals("2", app.string);
|
||||
@@ -2060,12 +2066,12 @@ public class CommandLineTest {
|
||||
A a = new A();
|
||||
CommandLine commandLine = new CommandLine(a);
|
||||
try {
|
||||
commandLine.parse("-u", "foo");
|
||||
commandLine.parseArgs("-u", "foo");
|
||||
fail("expected exception");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required option '--password=<password>'", ex.getLocalizedMessage());
|
||||
}
|
||||
commandLine.parse("-u", "foo", "-p", "abc");
|
||||
commandLine.parseArgs("-u", "foo", "-p", "abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2219,7 +2225,7 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new App()).setUnmatchedArgumentsAllowed(true);
|
||||
cmd.parse("1=a", "2=b", "3=c", "4=d");
|
||||
cmd.parseArgs("1=a", "2=b", "3=c", "4=d");
|
||||
assertEquals(Arrays.asList("3=c", "4=d"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
@Test
|
||||
@@ -2236,7 +2242,7 @@ public class CommandLineTest {
|
||||
}
|
||||
setTraceLevel("OFF");
|
||||
CommandLine cmd = new CommandLine(new App()).setUnmatchedArgumentsAllowed(true);
|
||||
cmd.parse("1=a", "2=b", "3=c", "4=d");
|
||||
cmd.parseArgs("1=a", "2=b", "3=c", "4=d");
|
||||
assertEquals(Arrays.asList("4=d"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
@Test
|
||||
@@ -2488,6 +2494,7 @@ public class CommandLineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void test149OnlyUnmatchedOptionStoredOthersParsed() throws Exception {
|
||||
class App {
|
||||
@@ -2567,20 +2574,20 @@ public class CommandLineTest {
|
||||
}
|
||||
App cmd1 = new App();
|
||||
CommandLine commandLine1 = new CommandLine(cmd1).setStopAtUnmatched(true);
|
||||
commandLine1.parse("--y", "-a=abc", "positional");
|
||||
commandLine1.parseArgs("--y", "-a=abc", "positional");
|
||||
assertEquals(Arrays.asList("--y", "-a=abc", "positional"), commandLine1.getUnmatchedArguments());
|
||||
assertNull(cmd1.first);
|
||||
assertNull(cmd1.positional);
|
||||
|
||||
try {
|
||||
// StopAtUnmatched=false, UnmatchedArgumentsAllowed=false
|
||||
new CommandLine(new App()).parse("--y", "-a=abc", "positional");
|
||||
new CommandLine(new App()).parseArgs("--y", "-a=abc", "positional");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unknown option: --y", ex.getMessage());
|
||||
}
|
||||
App cmd2 = new App();
|
||||
CommandLine commandLine2 = new CommandLine(cmd2).setStopAtUnmatched(false).setUnmatchedArgumentsAllowed(true);
|
||||
commandLine2.parse("--y", "-a=abc", "positional");
|
||||
commandLine2.parseArgs("--y", "-a=abc", "positional");
|
||||
assertEquals(Arrays.asList("--y"), commandLine2.getUnmatchedArguments());
|
||||
assertEquals("abc", cmd2.first);
|
||||
assertArrayEquals(new String[]{"positional"}, cmd2.positional);
|
||||
@@ -2611,7 +2618,7 @@ public class CommandLineTest {
|
||||
}
|
||||
App cmd1 = new App();
|
||||
CommandLine commandLine1 = new CommandLine(cmd1).setStopAtPositional(true);
|
||||
commandLine1.parse("positional", "-a=abc", "positional");
|
||||
commandLine1.parseArgs("positional", "-a=abc", "positional");
|
||||
assertArrayEquals(new String[]{"positional", "-a=abc", "positional"}, cmd1.positional);
|
||||
assertNull(cmd1.first);
|
||||
}
|
||||
@@ -2687,7 +2694,7 @@ public class CommandLineTest {
|
||||
// RP: After removing `usageHelp = true`, the "-o /tmp" argument is parsed as '-o'
|
||||
// with attached option value ' /tmp' (note the leading space).
|
||||
// A MissingParameterException is thrown for the missing <inputFiles>, as expected.
|
||||
new CommandLine(new Example()).parse("-o /tmp");
|
||||
new CommandLine(new Example()).parseArgs("-o /tmp");
|
||||
fail("Expected MissingParameterException");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required parameter: <inputFiles>", ex.getMessage());
|
||||
@@ -2697,14 +2704,14 @@ public class CommandLineTest {
|
||||
//
|
||||
// RP: After removing `usageHelp = true`, the ["-o", " /tmp"] arguments are parsed and
|
||||
// a MissingParameterException is thrown for the missing <inputFiles>, as expected.
|
||||
new CommandLine(new Example()).parse("-o", " /tmp");
|
||||
new CommandLine(new Example()).parseArgs("-o", " /tmp");
|
||||
fail("Expected MissingParameterException");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required parameter: <inputFiles>", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
// a MissingParameterException is thrown for missing required option -o, as expected
|
||||
new CommandLine(new Example()).parse("inputfile1", "inputfile2");
|
||||
new CommandLine(new Example()).parseArgs("inputfile1", "inputfile2");
|
||||
fail("Expected MissingParameterException");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required option '--out-dir=<outputDir>'", ex.getMessage());
|
||||
@@ -2712,7 +2719,7 @@ public class CommandLineTest {
|
||||
|
||||
// a single empty string parameter was specified: this becomes an <inputFile> value
|
||||
try {
|
||||
new CommandLine(new Example()).parse("");
|
||||
new CommandLine(new Example()).parseArgs("");
|
||||
fail("Expected MissingParameterException");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required option '--out-dir=<outputDir>'", ex.getMessage());
|
||||
@@ -2720,7 +2727,7 @@ public class CommandLineTest {
|
||||
|
||||
// no parameters were specified
|
||||
try {
|
||||
new CommandLine(new Example()).parse();
|
||||
new CommandLine(new Example()).parseArgs();
|
||||
fail("Expected MissingParameterException");
|
||||
} catch (MissingParameterException ex) {
|
||||
assertEquals("Missing required options [--out-dir=<outputDir>, params[0..*]=<inputFiles>]", ex.getMessage());
|
||||
@@ -2728,12 +2735,13 @@ public class CommandLineTest {
|
||||
|
||||
// finally, let's test the success scenario
|
||||
Example example = new Example();
|
||||
new CommandLine(example).parse("-o", "/tmp","inputfile1", "inputfile2");
|
||||
new CommandLine(example).parseArgs("-o", "/tmp","inputfile1", "inputfile2");
|
||||
assertEquals(new File("/tmp"), example.outputDir);
|
||||
assertEquals(2, example.inputFiles.length);
|
||||
assertEquals(new File("inputfile1"), example.inputFiles[0]);
|
||||
assertEquals(new File("inputfile2"), example.inputFiles[1]);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testIssue207ParameterExceptionProvidesAccessToFailedCommand_Programmatic() {
|
||||
class Top {
|
||||
@@ -2749,7 +2757,7 @@ public class CommandLineTest {
|
||||
new CommandLine(new Top()).
|
||||
addSubcommand("sub1", new Sub1()).
|
||||
addSubcommand("sub2", new Sub2()).
|
||||
parse("sub1 -x abc".split(" "));
|
||||
parseArgs("sub1 -x abc".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getCommandLine().getCommand() instanceof Top);
|
||||
}
|
||||
@@ -2757,7 +2765,7 @@ public class CommandLineTest {
|
||||
new CommandLine(new Top()).
|
||||
addSubcommand("sub1", new Sub1()).
|
||||
addSubcommand("sub2", new Sub2()).
|
||||
parse("-o OPT sub1 -wrong ABC".split(" "));
|
||||
parseArgs("-o OPT sub1 -wrong ABC".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getCommandLine().getCommand() instanceof Sub1);
|
||||
}
|
||||
@@ -2765,7 +2773,7 @@ public class CommandLineTest {
|
||||
new CommandLine(new Top()).
|
||||
addSubcommand("sub1", new Sub1()).
|
||||
addSubcommand("sub2", new Sub2()).
|
||||
parse("-o OPT sub2 -wrong ABC".split(" "));
|
||||
parseArgs("-o OPT sub2 -wrong ABC".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getCommandLine().getCommand() instanceof Sub2);
|
||||
}
|
||||
@@ -2781,6 +2789,8 @@ public class CommandLineTest {
|
||||
private static class Sub207A { @Option(names = "-x", required = true) String x; }
|
||||
@Command(name = "sub207B")
|
||||
private static class Sub207B { @Option(names = "-y", required = true) String y; }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testIssue207ParameterExceptionProvidesAccessToFailedCommand_Declarative() {
|
||||
@Command(subcommands = {Sub207A.class, Sub207B.class})
|
||||
@@ -2788,17 +2798,17 @@ public class CommandLineTest {
|
||||
@Option(names = "-o", required = true) String option;
|
||||
}
|
||||
try {
|
||||
new CommandLine(new Top()).parse("sub207A -x abc".split(" "));
|
||||
new CommandLine(new Top()).parseArgs("sub207A -x abc".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getCommandLine().getCommand() instanceof Top);
|
||||
}
|
||||
try {
|
||||
new CommandLine(new Top()).parse("-o OPT sub207A -wrong ABC".split(" "));
|
||||
new CommandLine(new Top()).parseArgs("-o OPT sub207A -wrong ABC".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getCommandLine().getCommand() instanceof Sub207A);
|
||||
}
|
||||
try {
|
||||
new CommandLine(new Top()).parse("-o OPT sub207B -wrong ABC".split(" "));
|
||||
new CommandLine(new Top()).parseArgs("-o OPT sub207B -wrong ABC".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertTrue(ex.getCommandLine().getCommand() instanceof Sub207B);
|
||||
}
|
||||
@@ -3097,7 +3107,7 @@ public class CommandLineTest {
|
||||
File file = findFile("/argfile1.txt");
|
||||
assertTrue(file.getAbsoluteFile().exists());
|
||||
App app = new App();
|
||||
new CommandLine(app).setExpandAtFiles(false).parse("@" + file.getAbsolutePath());
|
||||
new CommandLine(app).setExpandAtFiles(false).parseArgs("@" + file.getAbsolutePath());
|
||||
assertFalse(app.verbose);
|
||||
assertEquals(Arrays.asList("@" + file.getAbsolutePath()), app.files);
|
||||
}
|
||||
@@ -3172,7 +3182,7 @@ public class CommandLineTest {
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.setAtFileCommentChar(null);
|
||||
cmd.parse("-f", "fVal1", "@" + file.getAbsolutePath(), "-x", "-f", "fVal2");
|
||||
cmd.parseArgs("-f", "fVal1", "@" + file.getAbsolutePath(), "-x", "-f", "fVal2");
|
||||
assertTrue(app.verbose);
|
||||
assertEquals(Arrays.asList("#", "first", "comment", "1111", "2222", "#another", "comment", ";3333"), app.files);
|
||||
assertTrue(app.xxx);
|
||||
@@ -3198,7 +3208,7 @@ public class CommandLineTest {
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.setAtFileCommentChar(';');
|
||||
cmd.parse("-f", "fVal1", "@" + file.getAbsolutePath(), "-x", "-f", "fVal2");
|
||||
cmd.parseArgs("-f", "fVal1", "@" + file.getAbsolutePath(), "-x", "-f", "fVal2");
|
||||
assertTrue(app.verbose);
|
||||
assertEquals(Arrays.asList("#", "first", "comment", "1111", "2222", "#another", "comment"), app.files);
|
||||
assertTrue(app.xxx);
|
||||
@@ -3299,7 +3309,7 @@ public class CommandLineTest {
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app).setOverwrittenOptionsAllowed(true);
|
||||
commandLine.setToggleBooleanFlags(true);
|
||||
commandLine.parse("-f", "fVal1", "@" + file.getAbsolutePath(), "-x", "@" + file2.getAbsolutePath(), "-f", "fVal2");
|
||||
commandLine.parseArgs("-f", "fVal1", "@" + file.getAbsolutePath(), "-x", "@" + file2.getAbsolutePath(), "-f", "fVal2");
|
||||
assertFalse("invoked twice", app.verbose);
|
||||
assertEquals(Arrays.asList("1111", "2222", ";3333", "1111", "2222", "3333"), app.files);
|
||||
assertFalse("invoked twice", app.xxx);
|
||||
@@ -3331,7 +3341,7 @@ public class CommandLineTest {
|
||||
setTraceLevel("OFF");
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app).setOverwrittenOptionsAllowed(true);
|
||||
commandLine.parse("-f", "fVal1", "@" + file.getAbsolutePath(), "-f", "fVal2");
|
||||
commandLine.parseArgs("-f", "fVal1", "@" + file.getAbsolutePath(), "-f", "fVal2");
|
||||
assertTrue("invoked in argFile2", app.verbose);
|
||||
assertEquals(Arrays.asList("abcdefg", "1111", "2222", "3333"), app.files);
|
||||
assertTrue("invoked in argFile2", app.xxx);
|
||||
@@ -3363,7 +3373,7 @@ public class CommandLineTest {
|
||||
setTraceLevel("INFO");
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app).setOverwrittenOptionsAllowed(true);
|
||||
commandLine.parse("-f", "fVal1", "@" + localCopy.getAbsolutePath(), "-f", "fVal2");
|
||||
commandLine.parseArgs("-f", "fVal1", "@" + localCopy.getAbsolutePath(), "-f", "fVal2");
|
||||
assertEquals(Arrays.asList("abc defg", "xyz"), app.files);
|
||||
assertArrayEquals(new String[]{"fVal1", "fVal2"}, app.fff);
|
||||
assertFalse("not invoked", app.verbose);
|
||||
@@ -3400,7 +3410,7 @@ public class CommandLineTest {
|
||||
setTraceLevel("INFO");
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app).setOverwrittenOptionsAllowed(true);
|
||||
commandLine.parse("-f", "fVal1", "@" + file.getAbsolutePath(), "-f", "fVal2");
|
||||
commandLine.parseArgs("-f", "fVal1", "@" + file.getAbsolutePath(), "-f", "fVal2");
|
||||
assertEquals(Arrays.asList("abcdefg", "@" + nested.getName()), app.files);
|
||||
assertArrayEquals(new String[]{"fVal1", "fVal2"}, app.fff);
|
||||
assertFalse("never invoked", app.verbose);
|
||||
@@ -3469,7 +3479,7 @@ public class CommandLineTest {
|
||||
}
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app);
|
||||
commandLine.parse("-t", "-x", "abc");
|
||||
commandLine.parseArgs("-t", "-x", "abc");
|
||||
assertEquals(Arrays.asList("-t", "-x", "abc"), commandLine.getUnmatchedArguments());
|
||||
assertEquals(Arrays.asList("-t", "-x", "abc"), app.unmatched);
|
||||
}
|
||||
@@ -3483,7 +3493,7 @@ public class CommandLineTest {
|
||||
}
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app);
|
||||
commandLine.parse("-t", "-x", "abc");
|
||||
commandLine.parseArgs("-t", "-x", "abc");
|
||||
assertEquals(Arrays.asList("-t", "-x", "abc"), commandLine.getUnmatchedArguments());
|
||||
assertEquals(Arrays.asList("-t", "-x", "abc"), app.unmatched);
|
||||
}
|
||||
@@ -3497,7 +3507,7 @@ public class CommandLineTest {
|
||||
}
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app);
|
||||
commandLine.parse("-t", "-x", "abc");
|
||||
commandLine.parseArgs("-t", "-x", "abc");
|
||||
assertEquals(Arrays.asList("-t", "-x", "abc"), commandLine.getUnmatchedArguments());
|
||||
assertArrayEquals(new String[]{"-t", "-x", "abc"}, app.unmatched);
|
||||
}
|
||||
@@ -3514,7 +3524,7 @@ public class CommandLineTest {
|
||||
}
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app);
|
||||
commandLine.parse("-t", "-x", "abc");
|
||||
commandLine.parseArgs("-t", "-x", "abc");
|
||||
assertEquals(Arrays.asList("-t", "-x", "abc"), commandLine.getUnmatchedArguments());
|
||||
assertArrayEquals(new String[]{"-t", "-x", "abc"}, app.unmatched1);
|
||||
assertArrayEquals(new String[]{"-t", "-x", "abc"}, app.unmatched2);
|
||||
@@ -3529,7 +3539,7 @@ public class CommandLineTest {
|
||||
@Unmatched String[] unmatched;
|
||||
}
|
||||
CommandLine cmd = new CommandLine(new App());
|
||||
cmd.parse("a", "b");
|
||||
cmd.parseArgs("a", "b");
|
||||
assertEquals(Arrays.asList("a", "b"), cmd.getUnmatchedArguments());
|
||||
}
|
||||
|
||||
@@ -3651,7 +3661,7 @@ public class CommandLineTest {
|
||||
String mandatory;
|
||||
}
|
||||
CommandLine commandLine = new CommandLine(new Parent(), new InnerClassFactory(this));
|
||||
commandLine.parse("help");
|
||||
commandLine.parseArgs("help");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -3662,7 +3672,7 @@ public class CommandLineTest {
|
||||
String mandatory;
|
||||
}
|
||||
CommandLine commandLine = new CommandLine(new Parent(), new InnerClassFactory(this));
|
||||
commandLine.parse("help");
|
||||
commandLine.parseArgs("help");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -3673,7 +3683,7 @@ public class CommandLineTest {
|
||||
String mandatory;
|
||||
}
|
||||
CommandLine commandLine = new CommandLine(new Parent(), new InnerClassFactory(this));
|
||||
commandLine.parse("--help");
|
||||
commandLine.parseArgs("--help");
|
||||
assertTrue("No exceptions", true);
|
||||
}
|
||||
|
||||
@@ -3694,18 +3704,18 @@ public class CommandLineTest {
|
||||
assertFalse(flags.p0);
|
||||
assertTrue (flags.b);
|
||||
assertTrue (flags.p1);
|
||||
commandLine.parse("-a", "-b", "true", "false");
|
||||
commandLine.parseArgs("-a", "-b", "true", "false");
|
||||
assertFalse(!flags.a);
|
||||
assertTrue (!flags.b);
|
||||
assertFalse(!flags.p0);
|
||||
assertTrue (!flags.p1);
|
||||
commandLine.parse("-a", "-b", "true", "false");
|
||||
commandLine.parseArgs("-a", "-b", "true", "false");
|
||||
assertFalse(!flags.a);
|
||||
assertTrue (!flags.b);
|
||||
assertFalse(!flags.p0);
|
||||
assertTrue (!flags.p1);
|
||||
|
||||
commandLine.parse("-a", "-a", "-b", "-b", "true", "false");
|
||||
commandLine.parseArgs("-a", "-a", "-b", "-b", "true", "false");
|
||||
// multiple occurrences DO cancel each other out
|
||||
assertFalse(flags.a);
|
||||
assertTrue (flags.b);
|
||||
@@ -3729,20 +3739,20 @@ public class CommandLineTest {
|
||||
assertTrue (flags.b);
|
||||
assertFalse(flags.p0);
|
||||
assertTrue (flags.p1);
|
||||
commandLine.parse("-a", "-b", "true", "false");
|
||||
commandLine.parseArgs("-a", "-b", "true", "false");
|
||||
// specified flags now opposite of default
|
||||
assertTrue (flags.a);
|
||||
assertFalse(flags.b);
|
||||
assertTrue (flags.p0);
|
||||
assertFalse(flags.p1);
|
||||
commandLine.parse("-a", "-b", "true", "false");
|
||||
commandLine.parseArgs("-a", "-b", "true", "false");
|
||||
// specified flags again opposite of default
|
||||
assertTrue (flags.a);
|
||||
assertFalse(flags.b);
|
||||
assertTrue (flags.p0);
|
||||
assertFalse(flags.p1);
|
||||
|
||||
commandLine.parse("-a", "-a", "-b", "-b", "true", "false");
|
||||
commandLine.parseArgs("-a", "-a", "-b", "-b", "true", "false");
|
||||
// multiple occurrences do NOT cancel each other out
|
||||
assertTrue (flags.a);
|
||||
assertFalse(flags.b);
|
||||
|
||||
@@ -157,6 +157,7 @@ public class CommandLineTypeConversionTest {
|
||||
assertEquals("Driver", null, bean.aDriver);
|
||||
assertEquals("Timestamp", null, bean.aTimestamp);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTypeConversionSucceedsForValidInput() throws Exception {
|
||||
//Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
|
||||
@@ -260,15 +261,15 @@ public class CommandLineTypeConversionTest {
|
||||
};
|
||||
commandLine.registerConverter(Byte.class, converter);
|
||||
commandLine.registerConverter(Byte.TYPE, converter);
|
||||
commandLine.parse("-byte", "0x1F", "-Byte", "0x0F");
|
||||
commandLine.parseArgs("-byte", "0x1F", "-Byte", "0x0F");
|
||||
assertEquals(0x1F, bean.byteField);
|
||||
assertEquals(Byte.valueOf((byte) 0x0F), bean.aByteField);
|
||||
|
||||
commandLine.parse("-byte", "010", "-Byte", "010");
|
||||
commandLine.parseArgs("-byte", "010", "-Byte", "010");
|
||||
assertEquals(8, bean.byteField);
|
||||
assertEquals(Byte.valueOf((byte) 8), bean.aByteField);
|
||||
|
||||
commandLine.parse("-byte", "34", "-Byte", "34");
|
||||
commandLine.parseArgs("-byte", "34", "-Byte", "34");
|
||||
assertEquals(34, bean.byteField);
|
||||
assertEquals(Byte.valueOf((byte) 34), bean.aByteField);
|
||||
}
|
||||
@@ -292,15 +293,15 @@ public class CommandLineTypeConversionTest {
|
||||
};
|
||||
commandLine.registerConverter(Short.class, shortConverter);
|
||||
commandLine.registerConverter(Short.TYPE, shortConverter);
|
||||
commandLine.parse("-short", "0xFF", "-Short", "0x6FFE");
|
||||
commandLine.parseArgs("-short", "0xFF", "-Short", "0x6FFE");
|
||||
assertEquals(0xFF, bean.shortField);
|
||||
assertEquals(Short.valueOf((short) 0x6FFE), bean.aShortField);
|
||||
|
||||
commandLine.parse("-short", "010", "-Short", "010");
|
||||
commandLine.parseArgs("-short", "010", "-Short", "010");
|
||||
assertEquals(8, bean.shortField);
|
||||
assertEquals(Short.valueOf((short) 8), bean.aShortField);
|
||||
|
||||
commandLine.parse("-short", "34", "-Short", "34");
|
||||
commandLine.parseArgs("-short", "34", "-Short", "34");
|
||||
assertEquals(34, bean.shortField);
|
||||
assertEquals(Short.valueOf((short) 34), bean.aShortField);
|
||||
}
|
||||
@@ -324,15 +325,15 @@ public class CommandLineTypeConversionTest {
|
||||
};
|
||||
commandLine.registerConverter(Integer.class, intConverter);
|
||||
commandLine.registerConverter(Integer.TYPE, intConverter);
|
||||
commandLine.parse("-int", "0xFF", "-Integer", "0xFFFF");
|
||||
commandLine.parseArgs("-int", "0xFF", "-Integer", "0xFFFF");
|
||||
assertEquals(255, bean.intField);
|
||||
assertEquals(Integer.valueOf(0xFFFF), bean.anIntegerField);
|
||||
|
||||
commandLine.parse("-int", "010", "-Integer", "010");
|
||||
commandLine.parseArgs("-int", "010", "-Integer", "010");
|
||||
assertEquals(8, bean.intField);
|
||||
assertEquals(Integer.valueOf(8), bean.anIntegerField);
|
||||
|
||||
commandLine.parse("-int", "34", "-Integer", "34");
|
||||
commandLine.parseArgs("-int", "34", "-Integer", "34");
|
||||
assertEquals(34, bean.intField);
|
||||
assertEquals(Integer.valueOf(34), bean.anIntegerField);
|
||||
}
|
||||
@@ -356,33 +357,37 @@ public class CommandLineTypeConversionTest {
|
||||
};
|
||||
commandLine.registerConverter(Long.class, longConverter);
|
||||
commandLine.registerConverter(Long.TYPE, longConverter);
|
||||
commandLine.parse("-long", "0xAABBCC", "-Long", "0xAABBCCDD");
|
||||
commandLine.parseArgs("-long", "0xAABBCC", "-Long", "0xAABBCCDD");
|
||||
assertEquals(0xAABBCC, bean.longField);
|
||||
assertEquals(Long.valueOf(0xAABBCCDDL), bean.aLongField);
|
||||
|
||||
commandLine.parse("-long", "010", "-Long", "010");
|
||||
commandLine.parseArgs("-long", "010", "-Long", "010");
|
||||
assertEquals(8, bean.longField);
|
||||
assertEquals(Long.valueOf(8), bean.aLongField);
|
||||
|
||||
commandLine.parse("-long", "34", "-Long", "34");
|
||||
commandLine.parseArgs("-long", "34", "-Long", "34");
|
||||
assertEquals(34, bean.longField);
|
||||
assertEquals(Long.valueOf(34), bean.aLongField);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTimeFormatHHmmSupported() throws ParseException {
|
||||
SupportedTypes bean = CommandLine.populateCommand(new SupportedTypes(), "-Time", "23:59");
|
||||
assertEquals("Time", new Time(new SimpleDateFormat("HH:mm").parse("23:59").getTime()), bean.aTimeField);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTimeFormatHHmmssSupported() throws ParseException {
|
||||
SupportedTypes bean = CommandLine.populateCommand(new SupportedTypes(), "-Time", "23:59:58");
|
||||
assertEquals("Time", new Time(new SimpleDateFormat("HH:mm:ss").parse("23:59:58").getTime()), bean.aTimeField);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTimeFormatHHmmssDotSSSSupported() throws ParseException {
|
||||
SupportedTypes bean = CommandLine.populateCommand(new SupportedTypes(), "-Time", "23:59:58.123");
|
||||
assertEquals("Time", new Time(new SimpleDateFormat("HH:mm:ss.SSS").parse("23:59:58.123").getTime()), bean.aTimeField);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTimeFormatHHmmssCommaSSSSupported() throws ParseException {
|
||||
SupportedTypes bean = CommandLine.populateCommand(new SupportedTypes(), "-Time", "23:59:58,123");
|
||||
@@ -568,6 +573,7 @@ public class CommandLineTypeConversionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testRegisterCustomConverter() {
|
||||
class Glob {
|
||||
@@ -599,6 +605,7 @@ public class CommandLineTypeConversionTest {
|
||||
public final String glob;
|
||||
public MyGlob(String glob) { this.glob = glob; }
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testAnnotateCustomConverter() {
|
||||
class App {
|
||||
@@ -647,7 +654,7 @@ public class CommandLineTypeConversionTest {
|
||||
CommandLine commandLine = new CommandLine(app);
|
||||
|
||||
String[] args = {"-x", "1234", "-t", "BLOB", "CLOB", "5678"};
|
||||
commandLine.parse(args);
|
||||
commandLine.parseArgs(args);
|
||||
assertEquals(1234, app.normalIntOption);
|
||||
assertEquals(Types.BLOB, app.sqlTypeOption);
|
||||
assertEquals(Types.CLOB, app.sqlTypeParam);
|
||||
@@ -667,7 +674,7 @@ public class CommandLineTypeConversionTest {
|
||||
}
|
||||
CommandLine commandLine = new CommandLine(new App());
|
||||
try {
|
||||
commandLine.parse("anything");
|
||||
commandLine.parseArgs("anything");
|
||||
} catch (CommandLine.ParameterException ex) {
|
||||
assertEquals("Invalid value for positional parameter at index 0..* (<sqlTypeParam>): cannot convert 'anything' to int (java.lang.IllegalStateException: bad converter)", ex.getMessage());
|
||||
}
|
||||
@@ -689,7 +696,7 @@ public class CommandLineTypeConversionTest {
|
||||
}
|
||||
App app = new App();
|
||||
CommandLine commandLine = new CommandLine(app, new Plus23ConverterFactory());
|
||||
commandLine.parse("100");
|
||||
commandLine.parseArgs("100");
|
||||
assertEquals(123, app.converted);
|
||||
}
|
||||
static class EnumParams {
|
||||
@@ -723,7 +730,7 @@ public class CommandLineTypeConversionTest {
|
||||
@Test
|
||||
public void testEnumTypeConversionIsCaseInsensitiveIfConfigured() {
|
||||
EnumParams params = new EnumParams();
|
||||
new CommandLine(params).setCaseInsensitiveEnumValuesAllowed(true).parse(
|
||||
new CommandLine(params).setCaseInsensitiveEnumValuesAllowed(true).parseArgs(
|
||||
"-timeUnit sEcONds -timeUnitArray milliSeconds miCroSeConds -timeUnitList SEConds MiCROsEconds nanoSEConds".split(" "));
|
||||
assertEquals(SECONDS, params.timeUnit);
|
||||
assertArrayEquals(new TimeUnit[]{MILLISECONDS, TimeUnit.MICROSECONDS}, params.timeUnitArray);
|
||||
@@ -742,7 +749,7 @@ public class CommandLineTypeConversionTest {
|
||||
}
|
||||
App params = new App();
|
||||
try {
|
||||
new CommandLine(params).parse("-e big".split(" "));
|
||||
new CommandLine(params).parseArgs("-e big".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertEquals("Invalid value for option '-e': expected one of [BIG, SMALL, TINY] (case-sensitive) but was 'big'", ex.getMessage());
|
||||
}
|
||||
@@ -754,7 +761,7 @@ public class CommandLineTypeConversionTest {
|
||||
}
|
||||
App params = new App();
|
||||
try {
|
||||
new CommandLine(params).setCaseInsensitiveEnumValuesAllowed(true).parse("-e big".split(" "));
|
||||
new CommandLine(params).setCaseInsensitiveEnumValuesAllowed(true).parseArgs("-e big".split(" "));
|
||||
} catch (ParameterException ex) {
|
||||
assertEquals("Invalid value for option '-e': expected one of [BIG, SMALL, TINY] (case-insensitive) but was 'big'", ex.getMessage());
|
||||
}
|
||||
@@ -788,14 +795,14 @@ public class CommandLineTypeConversionTest {
|
||||
public void testArrayOptionParametersAreAlwaysInstantiated() {
|
||||
EnumParams params = new EnumParams();
|
||||
TimeUnit[] array = params.timeUnitArray;
|
||||
new CommandLine(params).parse("-timeUnitArray", "SECONDS", "MILLISECONDS");
|
||||
new CommandLine(params).parseArgs("-timeUnitArray", "SECONDS", "MILLISECONDS");
|
||||
assertNotSame(array, params.timeUnitArray);
|
||||
}
|
||||
@Test
|
||||
public void testListOptionParametersAreInstantiatedIfNull() {
|
||||
EnumParams params = new EnumParams();
|
||||
assertNull(params.timeUnitList);
|
||||
new CommandLine(params).parse("-timeUnitList", "SECONDS", "MICROSECONDS", "MILLISECONDS");
|
||||
new CommandLine(params).parseArgs("-timeUnitList", "SECONDS", "MICROSECONDS", "MILLISECONDS");
|
||||
assertEquals(Arrays.asList(SECONDS, MICROSECONDS, MILLISECONDS), params.timeUnitList);
|
||||
}
|
||||
@Test
|
||||
@@ -803,7 +810,7 @@ public class CommandLineTypeConversionTest {
|
||||
EnumParams params = new EnumParams();
|
||||
List<TimeUnit> list = new ArrayList<TimeUnit>();
|
||||
params.timeUnitList = list;
|
||||
new CommandLine(params).parse("-timeUnitList", "SECONDS", "MICROSECONDS", "SECONDS");
|
||||
new CommandLine(params).parseArgs("-timeUnitList", "SECONDS", "MICROSECONDS", "SECONDS");
|
||||
assertEquals(Arrays.asList(SECONDS, MICROSECONDS, SECONDS), params.timeUnitList);
|
||||
assertSame(list, params.timeUnitList);
|
||||
}
|
||||
@@ -817,7 +824,7 @@ public class CommandLineTypeConversionTest {
|
||||
ArrayList<String> list;
|
||||
}
|
||||
App params = new App();
|
||||
new CommandLine(params).parse("-list", "a", "-list", "b", "-map", "a=b");
|
||||
new CommandLine(params).parseArgs("-list", "a", "-list", "b", "-map", "a=b");
|
||||
assertEquals(Arrays.asList("a", "b"), params.list);
|
||||
|
||||
HashMap<String, String> expected = new HashMap<String, String>();
|
||||
|
||||
@@ -422,6 +422,7 @@ public class Demo implements Runnable {
|
||||
@Command(name = "git-tag", header = "Create, list, delete or verify a tag object signed with GPG.") static class GitTag{}
|
||||
|
||||
/** @see CommandLineTest#testParseSubCommands() The JUnit test implementation of this test. */
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void testParseSubCommands() {
|
||||
CommandLine commandLine = mainCommand();
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ public class InteractiveArgTest {
|
||||
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x");
|
||||
cmd.parseArgs("-x");
|
||||
|
||||
assertEquals("Enter value for -x (Pwd): ", baos.toString());
|
||||
assertEquals(123, app.x);
|
||||
assertEquals(0, app.z);
|
||||
|
||||
cmd.parse("-z", "678");
|
||||
cmd.parseArgs("-z", "678");
|
||||
|
||||
assertEquals(0, app.x);
|
||||
assertEquals(678, app.z);
|
||||
@@ -66,13 +66,13 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-x");
|
||||
cmd.parseArgs("-x", "-x");
|
||||
|
||||
assertEquals("Enter value for -x (Pwd): Enter value for -x (Pwd): ", baos.toString());
|
||||
assertEquals(Arrays.asList(123, 123), app.x);
|
||||
assertEquals(0, app.z);
|
||||
|
||||
cmd.parse("-z", "678");
|
||||
cmd.parseArgs("-z", "678");
|
||||
|
||||
assertNull(app.x);
|
||||
assertEquals(678, app.z);
|
||||
@@ -112,7 +112,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-x");
|
||||
cmd.parseArgs("-x", "-x");
|
||||
|
||||
assertEquals("Enter value for -x (Pwd): Enter value for -x (Pwd): ", baos.toString());
|
||||
assertEquals(2, app.x.size());
|
||||
@@ -120,7 +120,7 @@ public class InteractiveArgTest {
|
||||
assertArrayEquals("123".toCharArray(), app.x.get(1));
|
||||
assertEquals(0, app.z);
|
||||
|
||||
cmd.parse("-z", "678");
|
||||
cmd.parseArgs("-z", "678");
|
||||
|
||||
assertNull(app.x);
|
||||
assertEquals(678, app.z);
|
||||
@@ -148,7 +148,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x");
|
||||
cmd.parseArgs("-x");
|
||||
|
||||
assertEquals("Enter value for -x (Pwd): ", baos.toString());
|
||||
assertArrayEquals("123".toCharArray(), app.x);
|
||||
@@ -176,7 +176,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "456", "abc");
|
||||
cmd.parseArgs("-x", "456", "abc");
|
||||
|
||||
assertArrayEquals("456".toCharArray(), app.x);
|
||||
assertArrayEquals(new String[]{"abc"}, app.remainder);
|
||||
@@ -203,7 +203,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "456", "-x", "789", "abc");
|
||||
cmd.parseArgs("-x", "456", "-x", "789", "abc");
|
||||
|
||||
assertEquals(2, app.x.size());
|
||||
assertArrayEquals("456".toCharArray(), app.x.get(0));
|
||||
@@ -235,7 +235,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-z", "456", "abc");
|
||||
cmd.parseArgs("-x", "-z", "456", "abc");
|
||||
|
||||
assertArrayEquals("123".toCharArray(), app.x);
|
||||
assertEquals(456, app.z);
|
||||
@@ -266,7 +266,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-z", "456", "abc");
|
||||
cmd.parseArgs("-x", "-z", "456", "abc");
|
||||
|
||||
assertEquals(1, app.x.size());
|
||||
assertArrayEquals("123".toCharArray(), app.x.get(0));
|
||||
@@ -298,7 +298,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-y", "456", "abc");
|
||||
cmd.parseArgs("-x", "-y", "456", "abc");
|
||||
|
||||
assertArrayEquals("-y".toCharArray(), app.x);
|
||||
assertEquals(0, app.z);
|
||||
@@ -329,7 +329,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-y", "-x", "-w", "456", "abc");
|
||||
cmd.parseArgs("-x", "-y", "-x", "-w", "456", "abc");
|
||||
|
||||
assertEquals(2, app.x.size());
|
||||
assertArrayEquals("-y".toCharArray(), app.x.get(0));
|
||||
@@ -358,7 +358,7 @@ public class InteractiveArgTest {
|
||||
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("-x", "-z", "987");
|
||||
cmd.parseArgs("-x", "-z", "987");
|
||||
|
||||
String expectedPrompt = format("Enter value for -x (Pwd%nline2): ");
|
||||
assertEquals(expectedPrompt, baos.toString());
|
||||
@@ -386,7 +386,7 @@ public class InteractiveArgTest {
|
||||
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("987");
|
||||
cmd.parseArgs("987");
|
||||
|
||||
String expectedPrompt = format("Enter value for position 0 (Pwd%nline2): ");
|
||||
assertEquals(expectedPrompt, baos.toString());
|
||||
@@ -415,7 +415,7 @@ public class InteractiveArgTest {
|
||||
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("333", "987");
|
||||
cmd.parseArgs("333", "987");
|
||||
|
||||
String expectedPrompt = format("Enter value for position 1 (Pwd%nline2): ");
|
||||
assertEquals(expectedPrompt, baos.toString());
|
||||
@@ -502,7 +502,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("999");
|
||||
cmd.parseArgs("999");
|
||||
|
||||
assertEquals("Enter value for position 0 (Pwd): Enter value for position 1 (Pwd): ", baos.toString());
|
||||
assertEquals(2, app.x.size());
|
||||
@@ -531,7 +531,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("9");
|
||||
cmd.parseArgs("9");
|
||||
|
||||
assertEquals("Enter value for position 0 (Pwd): ", baos.toString());
|
||||
assertArrayEquals("123".toCharArray(), app.x);
|
||||
@@ -559,7 +559,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("456", "abc");
|
||||
cmd.parseArgs("456", "abc");
|
||||
|
||||
assertArrayEquals("456".toCharArray(), app.x);
|
||||
assertArrayEquals(new String[]{"abc"}, app.remainder);
|
||||
@@ -586,7 +586,7 @@ public class InteractiveArgTest {
|
||||
System.setIn(inputStream("123"));
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
cmd.parse("456", "789", "abc");
|
||||
cmd.parseArgs("456", "789", "abc");
|
||||
|
||||
assertEquals(2, app.x.size());
|
||||
assertArrayEquals("456".toCharArray(), app.x.get(0));
|
||||
@@ -619,7 +619,7 @@ public class InteractiveArgTest {
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
try {
|
||||
cmd.parse("-y", "456", "abc");
|
||||
cmd.parseArgs("-y", "456", "abc");
|
||||
fail("Expect exception");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unknown option: -y", ex.getMessage());
|
||||
@@ -651,7 +651,7 @@ public class InteractiveArgTest {
|
||||
App app = new App();
|
||||
CommandLine cmd = new CommandLine(app);
|
||||
try {
|
||||
cmd.parse("-y", "-w", "456", "abc");
|
||||
cmd.parseArgs("-y", "-w", "456", "abc");
|
||||
fail("Expect exception");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unknown options: -y, -w", ex.getMessage());
|
||||
|
||||
@@ -53,7 +53,7 @@ public class LenientParsingTest {
|
||||
spec.addOption(option);
|
||||
spec.parser().collectErrors(true);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("-c", "1", "2", "3");
|
||||
commandLine.parseArgs("-c", "1", "2", "3");
|
||||
assertEquals(1, commandLine.getParseResult().errors().size());
|
||||
assertEquals("Unmatched arguments: 2, 3", commandLine.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class LenientParsingTest {
|
||||
spec.addPositional(positional);
|
||||
spec.parser().collectErrors(true);
|
||||
CommandLine commandLine = new CommandLine(spec);
|
||||
commandLine.parse("1", "2", "3");
|
||||
commandLine.parseArgs("1", "2", "3");
|
||||
assertEquals(1, commandLine.getParseResult().errors().size());
|
||||
assertEquals("Unmatched arguments: 2, 3", commandLine.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class LenientParsingTest {
|
||||
|
||||
CommandLine cmd = new CommandLine(new Example());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse(new String[0]);
|
||||
cmd.parseArgs(new String[0]);
|
||||
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required parameter: <mandatory>", cmd.getParseResult().errors().get(0).getMessage());
|
||||
@@ -95,12 +95,12 @@ public class LenientParsingTest {
|
||||
CommandLine cmd = new CommandLine(new Tricky1());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
|
||||
cmd.parse(new String[0]);
|
||||
cmd.parseArgs(new String[0]);
|
||||
assertEquals(2, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required parameters: <mandatory>, <anotherMandatory>", cmd.getParseResult().errors().get(0).getMessage());
|
||||
assertEquals("Missing required parameter: <anotherMandatory>", cmd.getParseResult().errors().get(1).getMessage());
|
||||
|
||||
cmd.parse(new String[] {"firstonly"});
|
||||
cmd.parseArgs(new String[] {"firstonly"});
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required parameter: <anotherMandatory>", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class LenientParsingTest {
|
||||
CommandLine cmd = new CommandLine(new Tricky2());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
|
||||
cmd.parse(new String[0]);
|
||||
cmd.parseArgs(new String[0]);
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required parameter: <mandatory>", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -129,11 +129,11 @@ public class LenientParsingTest {
|
||||
CommandLine cmd = new CommandLine(new Tricky3());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
|
||||
cmd.parse(new String[] {"-t", "-v", "mandatory"});
|
||||
cmd.parseArgs(new String[] {"-t", "-v", "mandatory"});
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required parameter: <alsoMandatory>", cmd.getParseResult().errors().get(0).getMessage());
|
||||
|
||||
cmd.parse(new String[] {"-t"});
|
||||
cmd.parseArgs(new String[] {"-t"});
|
||||
assertEquals(3, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required options [-v, params[0]=<mandatory>, params[1]=<alsoMandatory>]", cmd.getParseResult().errors().get(0).getMessage());
|
||||
assertEquals("Missing required parameters: <mandatory>, <alsoMandatory>", cmd.getParseResult().errors().get(1).getMessage());
|
||||
@@ -148,7 +148,7 @@ public class LenientParsingTest {
|
||||
CommandLine cmd = new CommandLine(new Tricky3());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
|
||||
cmd.parse(new String[] {"-t"});
|
||||
cmd.parseArgs(new String[] {"-t"});
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Missing required parameter: <mandatory>", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -161,11 +161,11 @@ public class LenientParsingTest {
|
||||
}
|
||||
CommandLine cmd = new CommandLine(new NonVarArgArrayParamsZeroArity());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("a", "b", "c");
|
||||
cmd.parseArgs("a", "b", "c");
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Unmatched arguments: a, b, c", cmd.getParseResult().errors().get(0).getMessage());
|
||||
|
||||
cmd.parse("a");
|
||||
cmd.parseArgs("a");
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Unmatched argument: a", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class LenientParsingTest {
|
||||
}
|
||||
CommandLine cmd = new CommandLine(new App());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-Long", "-boolean");
|
||||
cmd.parseArgs("-Long", "-boolean");
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Invalid value for option '-Long': '-boolean' is not a long", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class LenientParsingTest {
|
||||
public void testBooleanOptionsArity0_nFailsIfAttachedParamNotABoolean() { // ignores varargs
|
||||
CommandLine cmd = new CommandLine(new CommandLineArityTest.BooleanOptionsArity0_nAndParameters());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-bool=123 -other".split(" "));
|
||||
cmd.parseArgs("-bool=123 -other".split(" "));
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Invalid value for option '-bool': '123' is not a boolean", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class LenientParsingTest {
|
||||
public void testBooleanOptionsArity0_nShortFormFailsIfAttachedParamNotABoolean() { // ignores varargs
|
||||
CommandLine cmd = new CommandLine(new CommandLineArityTest.BooleanOptionsArity0_nAndParameters());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-rv234 -bool".split(" "));
|
||||
cmd.parseArgs("-rv234 -bool".split(" "));
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Unknown option: -234 (while processing option: '-rv234')", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -263,7 +263,7 @@ public class LenientParsingTest {
|
||||
private void assertMissing(List<String> expected, Object command, String... args) {
|
||||
CommandLine cmd = new CommandLine(command);
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse(args);
|
||||
cmd.parseArgs(args);
|
||||
List<Exception> errors = cmd.getParseResult().errors();
|
||||
assertEquals(errors.toString(), expected.size(), errors.size());
|
||||
int i = 0;
|
||||
@@ -275,7 +275,7 @@ public class LenientParsingTest {
|
||||
public void testEnumListTypeConversionFailsForInvalidInput() {
|
||||
CommandLine cmd = new CommandLine(new CommandLineTypeConversionTest.EnumParams());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-timeUnitList", "SECONDS", "b", "c");
|
||||
cmd.parseArgs("-timeUnitList", "SECONDS", "b", "c");
|
||||
assertEquals(2, cmd.getParseResult().errors().size());
|
||||
Exception ex = cmd.getParseResult().errors().get(0);
|
||||
String prefix = "Invalid value for option '-timeUnitList' at index 1 (<timeUnitList>): expected one of ";
|
||||
@@ -289,7 +289,7 @@ public class LenientParsingTest {
|
||||
public void testTimeFormatHHmmssSSSInvalidError() throws ParseException {
|
||||
CommandLine cmd = new CommandLine(new CommandLineTypeConversionTest.SupportedTypes());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-Time", "23:59:58;123");
|
||||
cmd.parseArgs("-Time", "23:59:58;123");
|
||||
assertEquals(1, cmd.getParseResult().errors().size());
|
||||
assertEquals("Invalid value for option '-Time': '23:59:58;123' is not a HH:mm[:ss[.SSS]] time", cmd.getParseResult().errors().get(0).getMessage());
|
||||
}
|
||||
@@ -297,7 +297,7 @@ public class LenientParsingTest {
|
||||
public void testByteFieldsAreDecimal() {
|
||||
CommandLine cmd = new CommandLine(new CommandLineTypeConversionTest.SupportedTypes());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-byte", "0x1F", "-Byte", "0x0F");
|
||||
cmd.parseArgs("-byte", "0x1F", "-Byte", "0x0F");
|
||||
assertEquals(2, cmd.getParseResult().errors().size());
|
||||
assertEquals("Invalid value for option '-byte': '0x1F' is not a byte", cmd.getParseResult().errors().get(0).getMessage());
|
||||
assertEquals("Invalid value for option '-Byte': '0x0F' is not a byte", cmd.getParseResult().errors().get(1).getMessage());
|
||||
@@ -312,7 +312,7 @@ public class LenientParsingTest {
|
||||
|
||||
CommandLine cmd = new CommandLine(new App());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("NOT_AN_INT", "-x=b", "-unknown", "1", "2", "3");
|
||||
cmd.parseArgs("NOT_AN_INT", "-x=b", "-unknown", "1", "2", "3");
|
||||
ParseResult parseResult = cmd.getParseResult();
|
||||
assertEquals(Arrays.asList("NOT_AN_INT", "-unknown", "2", "3"), parseResult.unmatched());
|
||||
assertEquals(6, parseResult.errors().size());
|
||||
@@ -331,7 +331,7 @@ public class LenientParsingTest {
|
||||
}
|
||||
CommandLine cmd = new CommandLine(new App());
|
||||
cmd.getCommandSpec().parser().collectErrors(true);
|
||||
cmd.parse("-queue", "a,b,c");
|
||||
cmd.parseArgs("-queue", "a,b,c");
|
||||
|
||||
ParseResult parseResult = cmd.getParseResult();
|
||||
assertTrue(parseResult.unmatched().isEmpty());
|
||||
|
||||
@@ -156,7 +156,7 @@ public class NegatableOptionTest {
|
||||
App app = new App();
|
||||
assertFalse(app.a);
|
||||
|
||||
new CommandLine(app).parse(args);
|
||||
new CommandLine(app).parseArgs(args);
|
||||
assertTrue(app.a);
|
||||
assertFalse(app.longWithoutNo);
|
||||
assertFalse(app.longB);
|
||||
@@ -216,7 +216,7 @@ public class NegatableOptionTest {
|
||||
cmd.setNegatableOptionTransformer(createNegatableShortOptionsTransformer());
|
||||
|
||||
String[] args = { "-a", "+b", "-c", "+n" };
|
||||
cmd.parse(args);
|
||||
cmd.parseArgs(args);
|
||||
assertTrue(app.a);
|
||||
assertFalse(app.b);
|
||||
assertFalse(app.c);
|
||||
@@ -252,7 +252,7 @@ public class NegatableOptionTest {
|
||||
cmd.setNegatableOptionTransformer(transformer);
|
||||
|
||||
String[] args = { "-a", "+b", "-c", "+n" };
|
||||
cmd.parse(args);
|
||||
cmd.parseArgs(args);
|
||||
String expected = String.format("" +
|
||||
"Usage: <main class> [(+|-)a] [(+|-)b] [(+|-)c] [(+|-)n]%n" +
|
||||
" (+|-)a%n" +
|
||||
|
||||
@@ -49,6 +49,7 @@ public class ParentCommandTest {
|
||||
parent.result = result;
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParentInjectedOnParseWhenConfiguredAsSubcommand() {
|
||||
List<CommandLine> result = new CommandLine(new Top()).parse("-d/tmp/blah", "sub", "3");
|
||||
@@ -65,6 +66,7 @@ public class ParentCommandTest {
|
||||
assertEquals(new File("/tmp/blah"), top.baseDirectory);
|
||||
assertEquals(3 * "/tmp/blah".length(), top.result);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParentNotInjectedWhenConfiguredAsTopLevelCommand() {
|
||||
List<CommandLine> result = new CommandLine(new Sub()).parse("3");
|
||||
@@ -73,6 +75,7 @@ public class ParentCommandTest {
|
||||
assertEquals(3, sub.count);
|
||||
assertEquals(0, sub.result);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParentInjectedWhenAddedAsSubcommand() {
|
||||
class Top1 {
|
||||
|
||||
@@ -271,6 +271,7 @@ public class SubcommandTests {
|
||||
assertArrayEquals(new String[]{"t"}, subSpec.aliases());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParseNestedSubCommands() {
|
||||
// valid
|
||||
@@ -298,7 +299,7 @@ public class SubcommandTests {
|
||||
|
||||
// sub12 is not nested under sub11 so is not recognized
|
||||
try {
|
||||
createNestedCommand().parse("cmd1", "sub11", "sub12");
|
||||
createNestedCommand().parseArgs("cmd1", "sub11", "sub12");
|
||||
fail("Expected exception for sub12");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched argument: sub12", ex.getMessage());
|
||||
@@ -319,43 +320,44 @@ public class SubcommandTests {
|
||||
|
||||
// invalid
|
||||
try {
|
||||
createNestedCommand().parse("-a", "-b", "cmd1");
|
||||
createNestedCommand().parseArgs("-a", "-b", "cmd1");
|
||||
fail("unmatched option should prevents remainder to be parsed as command");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unknown option: -b", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
createNestedCommand().parse("cmd1", "sub21");
|
||||
createNestedCommand().parseArgs("cmd1", "sub21");
|
||||
fail("sub-commands for different parent command");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched argument: sub21", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
createNestedCommand().parse("cmd1", "sub22sub1");
|
||||
createNestedCommand().parseArgs("cmd1", "sub22sub1");
|
||||
fail("sub-sub-commands for different parent command");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched argument: sub22sub1", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
createNestedCommand().parse("sub11");
|
||||
createNestedCommand().parseArgs("sub11");
|
||||
fail("sub-commands without preceding parent command");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched argument: sub11", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
createNestedCommand().parse("sub21");
|
||||
createNestedCommand().parseArgs("sub21");
|
||||
fail("sub-commands without preceding parent command");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched argument: sub21", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
createNestedCommand().parse("sub22sub1");
|
||||
createNestedCommand().parseArgs("sub22sub1");
|
||||
fail("sub-sub-commands without preceding parent/grandparent command");
|
||||
} catch (UnmatchedArgumentException ex) {
|
||||
assertEquals("Unmatched argument: sub22sub1", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParseNestedSubCommandsWithAliases() {
|
||||
// valid
|
||||
@@ -403,6 +405,7 @@ public class SubcommandTests {
|
||||
assertTrue(((GreatGrandChild2Command2_1) sub22sub1WithOptions.get(3).getCommand()).h);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testParseNestedSubCommandsAllowingUnmatchedArguments() {
|
||||
setTraceLevel("OFF");
|
||||
@@ -578,7 +581,7 @@ public class SubcommandTests {
|
||||
@Test(expected = MissingTypeConverterException.class)
|
||||
public void testCustomTypeConverterNotRegisteredAtAll() {
|
||||
CommandLine commandLine = createNestedCommand();
|
||||
commandLine.parse("cmd1", "sub12", "-e", "TXT");
|
||||
commandLine.parseArgs("cmd1", "sub12", "-e", "TXT");
|
||||
}
|
||||
|
||||
@Test(expected = MissingTypeConverterException.class)
|
||||
@@ -589,9 +592,10 @@ public class SubcommandTests {
|
||||
commandLine.registerConverter(CustomType.class, new CustomType(null));
|
||||
|
||||
commandLine.addSubcommand("main", createNestedCommand());
|
||||
commandLine.parse("main", "cmd1", "sub12", "-e", "TXT");
|
||||
commandLine.parseArgs("main", "cmd1", "sub12", "-e", "TXT");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testCustomTypeConverterRegisteredAfterSubcommandsAdded() {
|
||||
@Command
|
||||
|
||||
Reference in New Issue
Block a user