Search in sources :

Example 1 with CommandLine

use of io.vertx.core.cli.CommandLine 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 2 with CommandLine

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

the class RunCommand method setUp.

/**
   * Validates the command line parameters.
   *
   * @param context - the execution context
   * @throws CLIException - validation failed
   */
@Override
public void setUp(ExecutionContext context) throws CLIException {
    super.setUp(context);
    // If cluster-host and / or port is set, cluster need to have been explicitly set
    io.vertx.core.cli.Option clusterHostOption = executionContext.cli().getOption("cluster-host");
    io.vertx.core.cli.Option clusterPortOption = executionContext.cli().getOption("cluster-port");
    CommandLine commandLine = executionContext.commandLine();
    if ((!isClustered()) && (commandLine.isOptionAssigned(clusterHostOption) || commandLine.isOptionAssigned(clusterPortOption))) {
        throw new CLIException("The option -cluster-host and -cluster-port requires -cluster to be enabled");
    }
    // If quorum and / or ha-group, ha need to have been explicitly set
    io.vertx.core.cli.Option haGroupOption = executionContext.cli().getOption("hagroup");
    io.vertx.core.cli.Option quorumOption = executionContext.cli().getOption("quorum");
    if (!ha && (commandLine.isOptionAssigned(haGroupOption) || commandLine.isOptionAssigned(quorumOption))) {
        throw new CLIException("The option -hagroup and -quorum requires -ha to be enabled");
    }
}
Also used : CommandLine(io.vertx.core.cli.CommandLine) CLIException(io.vertx.core.cli.CLIException)

Example 3 with CommandLine

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

the class CLIExamples method example8.

public void example8(CLI cli, List<String> userCommandLineArguments) {
    CommandLine commandLine = cli.parse(userCommandLineArguments);
    String opt = commandLine.getOptionValue("my-option");
    boolean flag = commandLine.isFlagEnabled("my-flag");
    String arg0 = commandLine.getArgumentValue(0);
}
Also used : CommandLine(io.vertx.core.cli.CommandLine)

Example 4 with CommandLine

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

Example 5 with CommandLine

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

the class TypedCLIExamples method example2.

public void example2(CLI cli, List<String> userCommandLineArguments) {
    CommandLine commandLine = cli.parse(userCommandLineArguments);
    boolean flag = commandLine.getOptionValue("R");
    File source = commandLine.getArgumentValue("source");
    File target = commandLine.getArgumentValue("target");
}
Also used : CommandLine(io.vertx.core.cli.CommandLine) File(java.io.File)

Aggregations

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