use of io.vertx.core.cli.Argument in project vert.x by eclipse.
the class DefaultParserTest method testThatOnlyTheLastArgumentCanBeMultivalued.
@Test(expected = CLIException.class)
public void testThatOnlyTheLastArgumentCanBeMultivalued() {
CLI cli = new DefaultCLI().setName("test");
cli.addArgument(new Argument().setIndex(0));
cli.addArgument(new Argument().setIndex(1).setMultiValued(true));
cli.addArgument(new Argument().setIndex(2));
cli.parse(Arrays.asList("a", "b", "c", "d"));
}
use of io.vertx.core.cli.Argument in project vert.x by eclipse.
the class DefaultParserTest method testWithMultipleArgumentReceivingSingleValues.
@Test
public void testWithMultipleArgumentReceivingSingleValues() {
CLI cli = new DefaultCLI().setName("test");
cli.addArgument(new Argument().setIndex(0));
cli.addArgument(new Argument().setIndex(1).setMultiValued(true));
CommandLine cl = cli.parse(Arrays.asList("a", "b"));
assertThat((String) cl.getArgumentValue(0)).isEqualTo("a");
assertThat(cl.getArgumentValues(1)).containsExactly("b");
assertThat((String) cl.getArgumentValue(1)).isEqualTo("b");
}
use of io.vertx.core.cli.Argument in project vert.x by eclipse.
the class DefaultParserTest method testThatArgumentIndexCanBeGenerated.
@Test
public void testThatArgumentIndexCanBeGenerated() {
CLI cli = new DefaultCLI().setName("test");
cli.addArgument(new Argument());
cli.addArgument(new Argument());
cli.addArgument(new Argument().setMultiValued(true));
CommandLine line = cli.parse(Arrays.asList("a", "b", "c", "d"));
assertThat((String) line.getArgumentValue(0)).isEqualToIgnoringCase("a");
assertThat((String) line.getArgumentValue(1)).isEqualToIgnoringCase("b");
assertThat(line.getArgumentValues(2)).containsExactly("c", "d");
}
use of io.vertx.core.cli.Argument in project vert.x by eclipse.
the class CLIExamples method example6.
public void example6() {
CLI cli = CLI.create("copy").setSummary("A command line interface to copy files.").addOption(new Option().setLongName("directory").setShortName("R").setDescription("enables directory support").setFlag(true)).addArgument(new Argument().setIndex(0).setDescription("The source").setArgName("source")).addArgument(new Argument().setIndex(0).setDescription("The destination").setArgName("target"));
StringBuilder builder = new StringBuilder();
cli.usage(builder);
}
use of io.vertx.core.cli.Argument in project vert.x by eclipse.
the class DefaultParserTest method testWithArgumentReceivingMultipleValues.
@Test
public void testWithArgumentReceivingMultipleValues() {
CLI cli = new DefaultCLI().setName("test");
cli.addArgument(new Argument().setIndex(0).setArgName("arg").setDescription("argument1"));
cli.addArgument(new Argument().setIndex(1).setMultiValued(true).setArgName("m").setDescription("multiple arg"));
CommandLine cl = cli.parse(Arrays.asList("a", "b", "c"));
assertThat((String) cl.getArgumentValue(0)).isEqualTo("a");
assertThat(cl.getArgumentValues(1)).containsExactly("b", "c");
assertThat((String) cl.getArgumentValue(1)).isEqualTo("b");
StringBuilder builder = new StringBuilder();
cli.usage(builder);
assertThat(builder).contains("test arg m...");
}