use of io.vertx.core.cli.CLI in project vert.x by eclipse.
the class DefaultCommandTest method testSystemProperties.
@Test
public void testSystemProperties() throws CLIException {
CLI cli = CLIConfigurator.define(command.getClass());
VertxCommandLauncher launcher = new VertxCommandLauncher();
CommandLine evaluatedCLI = parse(cli, "--name=vert.x", "-Dfoo=bar", "--systemProp=x=y");
CLIConfigurator.inject(evaluatedCLI, command);
command.setUp(new ExecutionContext(command, launcher, evaluatedCLI));
assertThat(System.getProperty("foo")).isEqualToIgnoringCase("bar");
assertThat(System.getProperty("x")).isEqualToIgnoringCase("y");
command.tearDown();
// System properties are not removed by the tearDown.
assertThat(System.getProperty("foo")).isEqualToIgnoringCase("bar");
assertThat(System.getProperty("x")).isEqualToIgnoringCase("y");
}
use of io.vertx.core.cli.CLI 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());
}
}
Aggregations