io.vertx.core.cli.CommandLine Java Examples

The following examples show how to use io.vertx.core.cli.CommandLine. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShellExamples.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
public void cliCommand() {
  CLI cli = CLI.create("my-command").
    addArgument(new Argument().setArgName("my-arg")).
    addOption(new Option().setShortName("m").setLongName("my-option"));
  CommandBuilder command = CommandBuilder.command(cli);
  command.processHandler(process -> {

    CommandLine commandLine = process.commandLine();

    String argValue = commandLine.getArgumentValue(0);
    String optValue = commandLine.getOptionValue("my-option");
    process.write("The argument is " + argValue + " and the option is " + optValue);

    process.end();
  });
}
 
Example #2
Source File: Main.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    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()
            .setDescription("The source")
            .setArgName("source"))
        .addArgument(new Argument()
            .setDescription("The target")
            .setArgName("target"));

    StringBuilder builder = new StringBuilder();
    cli.usage(builder);
    if (args.length < 3) {
        System.out.println(builder.toString());
        System.exit(0);
    }

    CommandLine commandLine = cli.parse(Arrays.asList(args));

    String sourceDir = commandLine.allArguments().get(0);
    String targetDir = commandLine.allArguments().get(1);

    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(SimpleVerticle.class.getName(), new DeploymentOptions()
        .setConfig(new JsonObject()
            .put("sourceDir", sourceDir)
            .put("targetDir", targetDir)), event -> {
        vertx.close();
        System.exit(0);
    });

}
 
Example #3
Source File: Main.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    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()
            .setDescription("The source")
            .setArgName("source"))
        .addArgument(new Argument()
            .setDescription("The target")
            .setArgName("target"));

    StringBuilder builder = new StringBuilder();
    cli.usage(builder);
    if (args.length < 3) {
        System.out.println(builder.toString());
        System.exit(0);
    }

    CommandLine commandLine = cli.parse(Arrays.asList(args));

    String sourceDir = commandLine.allArguments().get(0);
    String targetDir = commandLine.allArguments().get(1);

    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(SimpleVerticle.class.getName(), new DeploymentOptions()
        .setConfig(new JsonObject()
            .put("sourceDir", sourceDir)
            .put("targetDir", targetDir)), event -> {
        vertx.close();
        System.exit(0);
    });

}
 
Example #4
Source File: Cli.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private boolean parserArgs(String[] args) {

        CLI parser = new DefaultCLI().setName("broker-cli.jar");
        parser.addOption(new Option()
            .setLongName("command")
            .setShortName("c")
            .setRequired(true)
            .addChoice("purgeQueue")
            .addChoice("getMessageCount")
            .setDescription("Command to run on broker"));
        parser.addOption(new Option()
            .setLongName("queue")
            .setShortName("q")
            .setRequired(true)
            .setDescription("Queue to run command against"));

        StringBuilder builder = new StringBuilder();
        parser.usage(builder);

        try {
            CommandLine cl = parser.parse(Arrays.asList(args));
            this.command = cl.getOptionValue("c");
            this.queue = cl.getOptionValue("q");
            return true;
        } catch (Exception e) {
            log.info("\n" + builder.toString());
        }
        return false;
    }
 
Example #5
Source File: CommandProcess.java    From vertx-shell with Apache License 2.0 2 votes vote down vote up
/**
 * @return the command line object or null
 */
CommandLine commandLine();