Search in sources :

Example 6 with CLI

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

Example 7 with CLI

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

Aggregations

CLI (io.vertx.core.cli.CLI)7 CommandLine (io.vertx.core.cli.CommandLine)4 Option (io.vertx.core.cli.Option)2 CommandFactory (io.vertx.core.spi.launcher.CommandFactory)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Argument (io.vertx.core.cli.Argument)1 ExecutionContext (io.vertx.core.spi.launcher.ExecutionContext)1 File (java.io.File)1