Java 类io.vertx.core.cli.CLI 实例源码

项目:vertx-shell    文件:Examples.java   
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();
  });
}
项目:vertx-shell    文件:Examples.java   
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 -> {
    // ...
  });
}
项目:vertx-shell    文件:CommandBuilderImpl.java   
@Override
public Command build(Vertx vertx) {
  Context context = vertx.getOrCreateContext();
  return new Command() {
    @Override
    public String name() {
      return name;
    }
    @Override
    public CLI cli() {
      return cli;
    }

    @Override
    public Process createProcess(List<CliToken> args) {
      return new ProcessImpl(vertx, context, this, args, processHandler);
    }

    @Override
    public void complete(Completion completion) {
      if (completeHandler != null) {
        context.runOnContext(v -> {
          try {
            completeHandler.handle(completion);
          } catch (Throwable t) {
            completion.complete(Collections.emptyList());
            throw t;
          }
        });
      } else {
        Command.super.complete(completion);
      }
    }
  };
}
项目:vertx-shell    文件:Echo.java   
@Override
public CLI cli() {
  // CLI does not support variable arguments yet
  return null;
}
项目:vertx-shell    文件:Command.java   
/**
 * @return the command line interface, can be null
 */
default CLI cli() {
  return null;
}
项目:vertx-shell    文件:CommandBuilderImpl.java   
public CommandBuilderImpl(String name, CLI cli) {
  this.name = name;
  this.cli = cli;
}
项目:vertx-shell    文件:AnnotatedCommand.java   
/**
 * @return the command line interface, can be null
 */
public CLI cli() {
  return null;
}
项目:vertx-unit    文件:TestCommandFactory.java   
@Override
public CLI define() {
  CLI cli = super.define();
  cli.getArgument(0).setArgName("test-verticle");
  return cli;
}
项目:vertx-shell    文件:CommandBuilder.java   
/**
 * Create a new commmand with its {@link io.vertx.core.cli.CLI} descriptor. This command can then retrieve the parsed
 * {@link CommandProcess#commandLine()} when it executes to know get the command arguments and options.
 *
 * @param cli the cli to use
 * @return the command
 */
static CommandBuilder command(CLI cli) {
  return new CommandBuilderImpl(cli.getName(), cli);
}