Search in sources :

Example 1 with CLI

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

Example 2 with CLI

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

the class TypedCLIExamples method example4.

public void example4(List<String> userCommandLineArguments) {
    CLI cli = CLI.create(AnnotatedCli.class);
    CommandLine commandLine = cli.parse(userCommandLineArguments);
    AnnotatedCli instance = new AnnotatedCli();
    CLIConfigurator.inject(commandLine, instance);
}
Also used : CLI(io.vertx.core.cli.CLI) CommandLine(io.vertx.core.cli.CommandLine)

Example 3 with CLI

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

the class ServiceCommandLookupTest method ensureCommand.

private void ensureCommand(Collection<CommandFactory<?>> commands, String name) {
    List<CLI> clis = new ArrayList<>();
    for (CommandFactory command : commands) {
        CLI cli = command.define();
        clis.add(cli);
        if (cli.getName().equalsIgnoreCase(name)) {
            return;
        }
    }
    fail("Cannot find '" + name + "' in " + clis.stream().map(CLI::getName).collect(Collectors.toList()));
}
Also used : CLI(io.vertx.core.cli.CLI) ArrayList(java.util.ArrayList) CommandFactory(io.vertx.core.spi.launcher.CommandFactory)

Example 4 with CLI

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

the class ServiceCommandLoaderTest method ensureCommand.

private void ensureCommand(Collection<CommandFactory<?>> commands, String name) {
    List<CLI> clis = new ArrayList<>();
    for (CommandFactory command : commands) {
        CLI cli = command.define();
        clis.add(cli);
        if (cli.getName().equalsIgnoreCase(name)) {
            return;
        }
    }
    fail("Cannot find '" + name + "' in " + clis.stream().map(CLI::getName).collect(Collectors.toList()));
}
Also used : CLI(io.vertx.core.cli.CLI) ArrayList(java.util.ArrayList) CommandFactory(io.vertx.core.spi.launcher.CommandFactory)

Example 5 with CLI

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

the class DefaultCommandTest method testCWD.

@Test
public void testCWD() throws CLIException {
    CLI cli = CLIConfigurator.define(command.getClass());
    CommandLine evaluatedCLI = parse(cli, "--name=vert.x");
    CLIConfigurator.inject(evaluatedCLI, command);
    assertThat(command.getCwd()).isEqualTo(new File("."));
    evaluatedCLI = parse(cli, "--cwd=target", "--name=vert.x");
    CLIConfigurator.inject(evaluatedCLI, command);
    assertThat(command.getCwd()).isEqualTo(new File("target"));
}
Also used : CLI(io.vertx.core.cli.CLI) CommandLine(io.vertx.core.cli.CommandLine) File(java.io.File) Test(org.junit.Test)

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