com.beust.jcommander.internal.DefaultConsole Java Examples

The following examples show how to use com.beust.jcommander.internal.DefaultConsole. 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: CompletionCommand.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public Executable configure(PrintStream out, PrintStream err, String... args) {
  HelpFlags help = new HelpFlags();

  Zsh zsh = new Zsh();

  JCommander commander = JCommander.newBuilder()
    .programName("selenium")
    .addObject(help)
    .addCommand(zsh)
    .build();
  commander.setConsole(new DefaultConsole(out));

  return () -> {
    try {
      commander.parse(args);
    } catch (ParameterException e) {
      err.println(e.getMessage());
      commander.usage();
      return;
    }

    if (help.displayHelp(commander, out)) {
      return;
    }

    if (args.length == 0) {
      commander.parse();
    }

    switch (commander.getParsedCommand()) {
      case "zsh":
        outputZshCompletions(out);
        break;

      default:
        err.println("Unrecognised shell: " + commander.getParsedCommand());
        System.exit(1);
        break;
    }
  };
}
 
Example #2
Source File: TemplateGridCommand.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public final Executable configure(PrintStream out, PrintStream err, String... args) {
  HelpFlags helpFlags = new HelpFlags();
  ConfigFlags configFlags = new ConfigFlags();

  Set<Object> allFlags = new LinkedHashSet<>();

  allFlags.add(helpFlags);
  allFlags.add(configFlags);

  StreamSupport.stream(ServiceLoader.load(HasRoles.class).spliterator(), true)
    .filter(flags -> !Sets.intersection(getConfigurableRoles(), flags.getRoles()).isEmpty())
    .forEach(allFlags::add);

  allFlags.addAll(getFlagObjects());

  JCommander.Builder builder = JCommander.newBuilder().programName(getName());
  allFlags.forEach(builder::addObject);
  JCommander commander = builder.build();
  commander.setConsole(new DefaultConsole(out));

  return () -> {
    try {
      commander.parse(args);
    } catch (ParameterException e) {
      err.println(e.getMessage());
      commander.usage();
      return;
    }

    if (helpFlags.displayHelp(commander, out)) {
      return;
    }

    Set<Config> allConfigs = new LinkedHashSet<>();
    allConfigs.add(new EnvConfig());
    allConfigs.add(new ConcatenatingConfig(getSystemPropertiesConfigPrefix(), '.', System.getProperties()));
    allFlags.forEach(flags -> allConfigs.add(new AnnotatedConfig(flags)));
    allConfigs.add(configFlags.readConfigFiles());
    allConfigs.add(getDefaultConfig());

    Config config = new MemoizedConfig(new CompoundConfig(allConfigs.toArray(new Config[0])));

    if (configFlags.dumpConfig(config, out)) {
      return;
    }

    if (configFlags.dumpConfigHelp(config, getConfigurableRoles(), out)) {
      return;
    }

    LoggingOptions loggingOptions = new LoggingOptions(config);
    loggingOptions.configureLogging();

    execute(config);
  };
}