Search in sources :

Example 1 with Argument

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"));
}
Also used : Argument(io.vertx.core.cli.Argument) Test(org.junit.Test)

Example 2 with Argument

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");
}
Also used : Argument(io.vertx.core.cli.Argument) Test(org.junit.Test)

Example 3 with Argument

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");
}
Also used : Argument(io.vertx.core.cli.Argument) Test(org.junit.Test)

Example 4 with Argument

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);
}
Also used : CLI(io.vertx.core.cli.CLI) Argument(io.vertx.core.cli.Argument) Option(io.vertx.core.cli.Option)

Example 5 with Argument

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...");
}
Also used : Argument(io.vertx.core.cli.Argument) Test(org.junit.Test)

Aggregations

Argument (io.vertx.core.cli.Argument)7 Test (org.junit.Test)6 CLI (io.vertx.core.cli.CLI)1 Option (io.vertx.core.cli.Option)1