io.vertx.core.cli.Argument Java Examples

The following examples show how to use io.vertx.core.cli.Argument. 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: ShellExamples.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
public void cliCommandWithHelp() {
  CLI cli = CLI.create("my-command").
    addArgument(new Argument().setArgName("my-arg")).
    addOption(new Option().setArgName("help").setShortName("h").setLongName("help"));
  CommandBuilder command = CommandBuilder.command(cli);
  command.processHandler(process -> {
    // ...
  });
}