Search in sources :

Example 6 with Option

use of io.vertx.core.cli.Option in project vert.x by eclipse.

the class DefaultParserTest method testTheDifferentFormatForLongOption.

@Test
public void testTheDifferentFormatForLongOption() throws CLIException {
    Option[] options = new Option[] { new Option().setShortName("f").setLongName("file").setSingleValued(true) };
    cli.addOptions(Arrays.asList(options));
    CommandLine evaluated = cli.parse(Arrays.asList("--file", "hello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    evaluated = cli.parse(Collections.singletonList("--file=hello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    evaluated = cli.parse(Collections.singletonList("-filehello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    evaluated = cli.parse(Arrays.asList("--FILE", "hello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
}
Also used : Option(io.vertx.core.cli.Option) Test(org.junit.Test)

Example 7 with Option

use of io.vertx.core.cli.Option in project vert.x by eclipse.

the class DefaultParserTest method testWithOneShortOption.

@Test
public void testWithOneShortOption() throws CLIException {
    Option[] options = new Option[] { new Option().setShortName("f").setLongName("file").setSingleValued(true) };
    cli.addOptions(Arrays.asList(options));
    CommandLine evaluated = cli.parse(Collections.singletonList("-f=hello.txt"));
    assertThat(evaluated.cli().getOptions()).hasSize(1);
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    assertThat(evaluated.getOptionValues("f")).containsExactly("hello.txt");
}
Also used : Option(io.vertx.core.cli.Option) Test(org.junit.Test)

Example 8 with Option

use of io.vertx.core.cli.Option in project vert.x by eclipse.

the class DefaultParserTest method testTheDifferentFormatForShortOption.

@Test
public void testTheDifferentFormatForShortOption() throws CLIException {
    Option[] options = new Option[] { new Option().setShortName("f").setLongName("file").setSingleValued(true) };
    cli.addOptions(Arrays.asList(options));
    CommandLine evaluated = cli.parse(Arrays.asList("-f", "hello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    evaluated = cli.parse(Collections.singletonList("-f=hello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    evaluated = cli.parse(Collections.singletonList("-fhello.txt"));
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
}
Also used : Option(io.vertx.core.cli.Option) Test(org.junit.Test)

Example 9 with Option

use of io.vertx.core.cli.Option in project vert.x by eclipse.

the class DefaultParserTest method testQuotedValues.

@Test
public void testQuotedValues() throws CLIException {
    Option[] options = new Option[] { new Option().setShortName("f").setLongName("file").setSingleValued(true) };
    cli.addOptions(Arrays.asList(options));
    CommandLine evaluated = cli.parse(Arrays.asList("--file", "\"hello.txt\""));
    assertThat(evaluated.cli().getOptions()).hasSize(1);
    assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
    assertThat(evaluated.getOptionValues("f")).containsExactly("hello.txt");
}
Also used : Option(io.vertx.core.cli.Option) Test(org.junit.Test)

Example 10 with Option

use of io.vertx.core.cli.Option 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)

Aggregations

Option (io.vertx.core.cli.Option)13 Test (org.junit.Test)11 CLI (io.vertx.core.cli.CLI)2 Argument (io.vertx.core.cli.Argument)1 CommandLine (io.vertx.core.cli.CommandLine)1