org.apache.commons.cli.Options#getOptions ( )源码实例Demo

下面列出了org.apache.commons.cli.Options#getOptions ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: exhibitor   文件: ExhibitorCLI.java
private void logOptions(String sectionName, String prefix, Options options)
{
    if ( sectionName != null )
    {
        log.info("== " + sectionName + " ==");
    }

    //noinspection unchecked
    for ( Option option : (Iterable<? extends Option>)options.getOptions() )
    {
        if ( option.hasLongOpt() )
        {
            if ( option.hasArg() )
            {
                log.info(prefix + option.getLongOpt() + " <arg> - " + option.getDescription());
            }
            else
            {
                log.info(prefix + option.getLongOpt() + " - " + option.getDescription());
            }
        }
    }
}
 
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
	
	Options options = EQTLInteractionAnalyser.OPTIONS;
	
	System.out.println("| Short | Long | Description |");
	System.out.println("|-------|------|-------------|");
	
	for(Object optionO : options.getOptions()){
		Option option = (Option) optionO;
		System.out.print("| -");
		System.out.print(option.getOpt());
		System.out.print(" | --");
		System.out.print(option.getLongOpt());
		System.out.print(" | ");
		System.out.print(option.getDescription());
		System.out.println(" | ");
	}
	
}
 
源代码3 项目: jstorm   文件: GenericOptionsParser.java
static Options buildGeneralOptions(Options opts) {
    Options r = new Options();

    for (Object o : opts.getOptions())
        r.addOption((Option) o);

    Option libjars =
            OptionBuilder.withArgName("paths").hasArg().withDescription("comma separated jars to be used by the submitted topology").create("libjars");
    r.addOption(libjars);
    optionProcessors.put("libjars", new LibjarsProcessor());

    Option conf = OptionBuilder.withArgName("configuration file").hasArg().withDescription("an application configuration file").create("conf");
    r.addOption(conf);
    optionProcessors.put("conf", new ConfFileProcessor());

    // Must come after `conf': this option is of higher priority
    Option extraConfig = OptionBuilder.withArgName("D").hasArg().withDescription("extra configurations (preserving types)").create("D");
    r.addOption(extraConfig);
    optionProcessors.put("D", new ExtraConfigProcessor());

    return r;
}
 
源代码4 项目: jstorm   文件: gray_upgrade.java
private static Options buildGeneralOptions(Options opts) {
    Options r = new Options();

    for (Object o : opts.getOptions())
        r.addOption((Option) o);

    Option workerNum = OptionBuilder.withArgName("worker num per batch").hasArg()
            .withDescription("number of workers to upgrade").create("n");
    r.addOption(workerNum);

    Option comp = OptionBuilder.withArgName("component to upgrade").hasArg()
            .withDescription("component id to upgrade, note that only one component is allowed at a time")
            .create("p");
    r.addOption(comp);

    Option workers = OptionBuilder.withArgName("workers to upgrade").hasArg()
            .withDescription("workers to upgrade, in the format: host1:port1,host2:port2,...").create("w");
    r.addOption(workers);

    return r;
}
 
源代码5 项目: rocketmq   文件: AbstractService.java
protected Collection<Option> getOptions(SubCommand subCommand) {
    Options options = new Options();
    subCommand.buildCommandlineOptions(options);
    @SuppressWarnings("unchecked")
    Collection<Option> col = options.getOptions();
    return col;
}
 
源代码6 项目: exhibitor   文件: ExhibitorCLI.java
private void addAll(String sectionName, Options adding)
{
    //noinspection unchecked
    for ( Option o : (Iterable<? extends Option>)adding.getOptions() )
    {
        options.addOption(o);
    }

    if ( sectionName != null )
    {
        sections.add(new OptionSection(sectionName, adding));
    }
}
 
源代码7 项目: attic-stratos   文件: CommandCompleter.java
public CommandCompleter(Map<String, Command<StratosCommandContext>> commands) {
    if (logger.isDebugEnabled()) {
        logger.debug("Creating auto complete for {} commands", commands.size());
    }
    fileNameCompleter = new StratosFileNameCompleter();
    argumentMap = new HashMap<String, Collection<String>>();
    defaultCommandCompleter = new StringsCompleter(commands.keySet());
    helpCommandCompleter = new ArgumentCompleter(new StringsCompleter(CliConstants.HELP_ACTION),
            defaultCommandCompleter);
    for (String action : commands.keySet()) {

        Command<StratosCommandContext> command = commands.get(action);
        Options commandOptions = command.getOptions();
        if (commandOptions != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Creating argument completer for command: {}", action);
            }
            List<String> arguments = new ArrayList<String>();
            Collection<?> allOptions = commandOptions.getOptions();
            for (Object o : allOptions) {
                Option option = (Option) o;
                String longOpt = option.getLongOpt();
                String opt = option.getOpt();
                if (StringUtils.isNotBlank(longOpt)) {
                    arguments.add("--" + longOpt);
                } else if (StringUtils.isNotBlank(opt)) {
                    arguments.add("-" + opt);
                }
            }

            argumentMap.put(action, arguments);
        }
    }
}
 
源代码8 项目: parquet-mr   文件: Main.java
public static void mergeOptionsInto(Options opt, Options opts) {
  if (opts == null) {
    return;
  }

  Collection<Option> all = opts.getOptions();
  if (all != null && !all.isEmpty()) {
    for (Option o : all) {
      opt.addOption(o);
    }
  }
}
 
源代码9 项目: parquet-tools   文件: Main.java
public static void mergeOptionsInto(Options opt, Options opts) {
  if (opts == null) {
    return;
  }

  Collection<Option> all = opts.getOptions();
  if (all != null && !all.isEmpty()) {
    for (Option o : all) {
      opt.addOption(o);
    }
  }
}
 
源代码10 项目: tez   文件: TezAnalyzerBase.java
private void printUsage() {
  System.err.println("Analyzer base options are");
  Options options = buildOptions();
  for (Object obj : options.getOptions()) {
    Option option = (Option) obj;
    System.err.println(option.getArgName() + " : " + option.getDescription());
  }
}
 
源代码11 项目: ade   文件: AdeExtOptions.java
public static Options buildOptions(Options subClassOptions) {
    /* Add the options from subClass */
    Options options = new Options();
    for (Object subClassOption : subClassOptions.getOptions()) {
        Option option = (Option) subClassOption;
        options.addOption(option);
    }

    /* Add the general options */
    OptionBuilder.withArgName(OPTION_HELP);
    OptionBuilder.withLongOpt(OPTION_HELP);
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Print help message and exit");
    options.addOption(OptionBuilder.create('h'));

    OptionBuilder.withArgName(OPTION_INPUT_FILE);
    OptionBuilder.withLongOpt(OPTION_INPUT_FILE);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Input file name or 'stdin'");
    options.addOption(OptionBuilder.create('f'));

    OptionBuilder.withArgName(OPTION_INPUT_DIR);
    OptionBuilder.withLongOpt(OPTION_INPUT_DIR);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Input dir name");
    options.addOption(OptionBuilder.create('d'));

    OptionBuilder.withArgName(OPTION_SOURCES);
    OptionBuilder.withLongOpt(OPTION_SOURCES);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Source Names.");
    options.addOption(OptionBuilder.create('s'));

    OptionBuilder.withArgName(OPTION_OS_TYPE);
    OptionBuilder.withLongOpt(OPTION_OS_TYPE);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("The OS Type."
            + "If this option is omitted, the default is Linux");
    options.addOption(OptionBuilder.create('o'));

    OptionBuilder.withArgName(OPTION_GMT_OFFSET);
    OptionBuilder.withLongOpt(OPTION_GMT_OFFSET);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("hours offset from GMT");
    options.addOption(OptionBuilder.create('g'));

    return options;
}
 
源代码12 项目: kieker   文件: CLIHelpFormatter.java
@SuppressWarnings("unchecked")
@Override
protected StringBuffer renderOptions(final StringBuffer sb, final int width, final Options options, final int leftPad, final int descPad) {
	final String lpad = this.createPadding(leftPad);
	final String dpad = this.createPadding(8); // we use a fixed value instead of descPad

	StringBuilder optBuf;

	final List<Option> optList = new ArrayList<Option>(options.getOptions());
	Collections.sort(optList, this.getOptionComparator());

	for (final Iterator<Option> i = optList.iterator(); i.hasNext();) {
		final Option option = i.next();

		optBuf = new StringBuilder(8);

		if (option.getOpt() == null) {
			optBuf.append(lpad).append("   ").append(this.getLongOptPrefix()).append(option.getLongOpt());
		} else {
			optBuf.append(lpad).append(this.getOptPrefix()).append(option.getOpt());

			if (option.hasLongOpt()) {
				optBuf.append(',').append(this.getLongOptPrefix()).append(option.getLongOpt());
			}
		}

		if (option.hasArg()) {
			if (option.hasArgName()) {
				optBuf.append(" <").append(option.getArgName()).append('>');
			} else {
				optBuf.append(' ');
			}
		}

		sb.append(optBuf.toString()).append(this.getNewLine());

		optBuf = new StringBuilder();
		optBuf.append(dpad);

		if (option.getDescription() != null) {
			optBuf.append(option.getDescription());
		}

		this.renderWrappedText(sb, width, dpad.length(), optBuf.toString());

		if (i.hasNext()) {
			sb.append(this.getNewLine());
			sb.append(this.getNewLine());
		}
	}

	return sb;
}
 
源代码13 项目: sarl   文件: MarkdownExtensions.java
/** Render the option help to a Markdown table.
 *
 * @param options the options.
 * @return the markdown table.
 */
protected static String _renderToMarkdown(Options options) {
	if (options == null) {
		return ""; //$NON-NLS-1$
	}
	final List<Option> optList = new ArrayList<>(options.getOptions());
	if (optList.isEmpty()) {
		return ""; //$NON-NLS-1$
	}
	Collections.sort(optList, new OptionComparator());

	final StringBuilder buffer = new StringBuilder();
	for (final Option option : optList) {
		buffer.append("| `"); //$NON-NLS-1$
		if (option.getOpt() == null) {
			buffer.append(DEFAULT_LONG_OPT_PREFIX).append(option.getLongOpt());
		} else {
			buffer.append(DEFAULT_OPT_PREFIX).append(option.getOpt());
			if (option.hasLongOpt()) {
				buffer.append("`, `"); //$NON-NLS-1$
				buffer.append(DEFAULT_LONG_OPT_PREFIX).append(option.getLongOpt());
			}
		}

		if (option.hasArg()) {
			if (option.hasArgName()) {
				buffer.append(" <").append(option.getArgName()).append(">"); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}

		buffer.append("` | "); //$NON-NLS-1$

		if (option.getDescription() != null) {
			String text = option.getDescription().replaceAll("[ \t\n\r\f]+", " "); //$NON-NLS-1$ //$NON-NLS-2$
			text = text.replaceAll("\\<", "&lt;");  //$NON-NLS-1$//$NON-NLS-2$
			text = text.replaceAll("\\>", "&gt;");  //$NON-NLS-1$//$NON-NLS-2$
			buffer.append(text);
		}

		buffer.append(" |\n"); //$NON-NLS-1$
	}

	return buffer.toString();
}