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);
}
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");
}
}
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);
}
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());
}
}
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");
}
Aggregations