Example usage for io.vertx.core.cli Option Option

List of usage examples for io.vertx.core.cli Option Option

Introduction

In this page you can find the example usage for io.vertx.core.cli Option Option.

Prototype

public Option() 

Source Link

Document

Creates a new empty instance of Option .

Usage

From source file:examples.cli.CLIExamples.java

License:Open Source License

public void example1() {
    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(1).setDescription("The destination").setArgName("target"));
}

From source file:examples.cli.CLIExamples.java

License:Open Source License

public void example2() {
    CLI cli = CLI.create("some-name").setSummary("A command line interface illustrating the options valuation.")
            .addOption(//w w  w  .j a v  a  2 s  .  c o m
                    new Option().setLongName("flag").setShortName("f").setFlag(true).setDescription("a flag"))
            .addOption(new Option().setLongName("single").setShortName("s")
                    .setDescription("a single-valued option"))
            .addOption(new Option().setLongName("multiple").setShortName("m").setMultiValued(true)
                    .setDescription("a multi-valued option"));
}

From source file:examples.cli.CLIExamples.java

License:Open Source License

public void example3() {
    CLI cli = CLI.create("some-name").addOption(
            new Option().setLongName("mandatory").setRequired(true).setDescription("a mandatory option"));
}

From source file:examples.cli.CLIExamples.java

License:Open Source License

public void example4() {
    CLI cli = CLI.create("some-name").addOption(new Option().setLongName("optional").setDefaultValue("hello")
            .setDescription("an optional option with a default value"));
}

From source file:examples.cli.CLIExamples.java

License:Open Source License

public void example41() {
    CLI cli = CLI.create("some-name").addOption(new Option().setLongName("color").setDefaultValue("green")
            .addChoice("blue").addChoice("red").addChoice("green").setDescription("a color"));
}

From source file:examples.cli.CLIExamples.java

License:Open Source License

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);/*from www .j av a2 s. c  o  m*/
}

From source file:examples.cli.CLIExamples.java

License:Open Source License

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);/*  w  ww.j a v a  2 s  .c  o  m*/
        stream.print(builder.toString());
    }
}

From source file:examples.ShellExamples.java

License:Open Source License

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();/* w  ww .java2  s  .  com*/
    });
}

From source file:examples.ShellExamples.java

License:Open Source License

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 -> {
        // ...//from  www.  j  a va  2s . c o m
    });
}