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");
}
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");
}
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");
}
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");
}
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);
}
Aggregations