use of io.vertx.core.cli.Option in project vert.x by eclipse.
the class CLIExamples method example9.
public void example9(PrintStream stream) {
CLI cli = CLI.create("test").addOption(new Option().setLongName("help").setShortName("h").setFlag(true).setHelp(true)).addOption(new Option().setLongName("mandatory").setRequired(true));
CommandLine line = cli.parse(Collections.singletonList("-h"));
// The parsing does not fail and let you do:
if (!line.isValid() && line.isAskingForHelp()) {
StringBuilder builder = new StringBuilder();
cli.usage(builder);
stream.print(builder.toString());
}
}
use of io.vertx.core.cli.Option in project vert.x by eclipse.
the class DefaultParserTest method testWithOneShortOptionUsingSpace.
@Test
public void testWithOneShortOptionUsingSpace() 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(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 testWithMultipleValues.
@Test
public void testWithMultipleValues() throws CLIException {
Option[] options = new Option[] { new Option().setShortName("f").setLongName("file").setMultiValued(true) };
cli.addOptions(Arrays.asList(options));
CommandLine evaluated = cli.parse(Arrays.asList("-f=hello.txt", "--file=hello2.txt"));
assertThat(evaluated.cli().getOptions()).hasSize(1);
assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt");
assertThat(evaluated.getOptionValues("f")).containsExactly("hello.txt", "hello2.txt");
}
Aggregations