List of usage examples for org.apache.commons.cli Option getOpt
public String getOpt()
From source file:com.ericsson.eiffel.remrem.publish.cli.CliOptions.java
public static void checkRequiredOptions() throws MissingOptionException { OptionGroup[] groups = { contentGroup }; for (OptionGroup group : groups) { ArrayList<Option> groupOptions = new ArrayList<Option>(group.getOptions()); boolean groupIsGiven = false; for (Option option : groupOptions) { if (commandLine.hasOption(option.getOpt())) { groupIsGiven = true;/* w w w . j a va2 s . c om*/ break; } } if (!groupIsGiven) { throw new MissingOptionException(groupOptions); } } }
From source file:com.asakusafw.yaess.tools.log.cli.Main.java
private static <T> T create(CommandLine cmd, Option opt, Class<T> type, ClassLoader loader) { assert cmd != null; assert opt != null; assert type != null; assert loader != null; String value = cmd.getOptionValue(opt.getOpt()); Class<?> aClass;/*from ww w. j a va2 s . c o m*/ try { aClass = Class.forName(value, false, loader); } catch (ClassNotFoundException e) { throw new IllegalArgumentException( MessageFormat.format("Failed to initialize the class \"{1}\" (-{0})", opt.getOpt(), value), e); } if (type.isAssignableFrom(aClass) == false) { throw new IllegalArgumentException(MessageFormat.format("\"{1}\" must be a subtype of \"{2}\" (-{0})", opt.getOpt(), value, type.getName())); } try { return aClass.asSubclass(type).getConstructor().newInstance(); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format("Failed to initialize the class \"{1}\" (-{0})", opt.getOpt(), value), e); } }
From source file:name.livitski.databag.cli.Syntax.java
protected static String getOptionId(Option option) { return option.hasLongOpt() ? LONG_OPT_PREFIX + option.getLongOpt() : OPT_PREFIX + option.getOpt(); }
From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java
public final static boolean hasSingleLetterOption(CommandLine commandLine, char option, String... excludes) { Option[] options = commandLine.getOptions(); for (Option option2 : options) { boolean skip = false; if (excludes != null) { for (String exclude : excludes) { if (option2.getOpt().equals(exclude)) { skip = true;/*from ww w . jav a 2 s .co m*/ break; } } } if (skip == false && option2.getOpt().indexOf(option) != -1) { return true; } } return false; }
From source file:com.asakusafw.dmdl.thundergate.Main.java
private static String getOption(CommandLine cmd, Option option, boolean mandatory) { assert cmd != null; assert option != null; String value = cmd.getOptionValue(option.getOpt()); if (mandatory && value == null) { throw new IllegalStateException(MessageFormat .format("\"{0}\"??????", option.getOpt())); }/*from ww w .j a v a2 s. c o m*/ LOG.debug("Option: {}={}", option.getOpt(), value); return value; }
From source file:eu.project.ttc.tools.cli.TermSuiteCLIUtils.java
/** * Returns the key of the given option//from www .ja va 2 s . c om * * @param opt * The option * @return {@link Option#getOpt()} if the value returned is not empty, or * {@link Option#getLongOpt()} otherwise. */ public static String getOptionKey(Option opt) { String key = opt.getOpt(); if (key == null || key.isEmpty()) key = opt.getLongOpt(); return key; }
From source file:io.janusproject.Boot.java
private static void parseCommandLineForVerbosity(CommandLine cmd) { // The order of the options is important. int verbose = LoggerCreator.toInt(JanusConfig.VERBOSE_LEVEL_VALUE); if (cmd.hasOption('v') || cmd.hasOption('q') || cmd.hasOption('l')) { @SuppressWarnings("unchecked") Iterator<Option> optIterator = cmd.iterator(); while (optIterator.hasNext()) { Option opt = optIterator.next(); switch (opt.getOpt()) { case "l": //$NON-NLS-1$ verbose = LoggerCreator.toInt(opt.getValue()); break; case "q": //$NON-NLS-1$ --verbose;//from w w w . j av a2 s . c o m break; case "v": //$NON-NLS-1$ ++verbose; break; default: } } System.setProperty(JanusConfig.VERBOSE_LEVEL_NAME, Integer.toString(verbose)); } // Show the Janus logo? if (cmd.hasOption("nologo") || verbose == 0) { //$NON-NLS-1$ System.setProperty(JanusConfig.JANUS_LOGO_SHOW_NAME, Boolean.FALSE.toString()); } }
From source file:alluxio.cli.ValidateEnv.java
private static boolean validateLocal(String target, String name, CommandLine cmd) throws InterruptedException { int validationCount = 0; Map<ValidationTask.TaskResult, Integer> results = new HashMap<>(); Map<String, String> optionsMap = new HashMap<>(); for (Option opt : cmd.getOptions()) { optionsMap.put(opt.getOpt(), opt.getValue()); }//from w w w. java 2s . co m Collection<ValidationTask> tasks = TARGET_TASKS.get(target); System.out.format("Validating %s environment...%n", target); for (ValidationTask task : tasks) { String taskName = TASKS.get(task); if (name != null && !taskName.startsWith(name)) { continue; } System.out.format("Validating %s...%n", taskName); ValidationTask.TaskResult result = task.validate(optionsMap); results.put(result, results.getOrDefault(result, 0) + 1); switch (result) { case OK: System.out.print(Constants.ANSI_GREEN); break; case WARNING: System.out.print(Constants.ANSI_YELLOW); break; case FAILED: System.out.print(Constants.ANSI_RED); break; case SKIPPED: System.out.print(Constants.ANSI_PURPLE); break; default: break; } System.out.print(result.name()); System.out.println(Constants.ANSI_RESET); validationCount++; } if (results.containsKey(ValidationTask.TaskResult.FAILED)) { System.err.format("%d failures ", results.get(ValidationTask.TaskResult.FAILED)); } if (results.containsKey(ValidationTask.TaskResult.WARNING)) { System.err.format("%d warnings ", results.get(ValidationTask.TaskResult.WARNING)); } if (results.containsKey(ValidationTask.TaskResult.SKIPPED)) { System.err.format("%d skipped ", results.get(ValidationTask.TaskResult.SKIPPED)); } System.err.println(); if (validationCount == 0) { System.err.format("No validation task matched name \"%s\".%n", name); return false; } if (results.containsKey(ValidationTask.TaskResult.FAILED)) { return false; } System.out.println("Validation succeeded."); return true; }
From source file:com.smartmarmot.dbforbix.DBforBix.java
private static void displayUsage() { System.out.println(Constants.BANNER); for (Option o : ((Collection<Option>) options.getOptions())) System.out.println("\t-" + o.getOpt() + "\t" + o.getDescription()); }
From source file:com.google.caja.plugin.Config.java
private static String[] getOptionValues(CommandLine cl, Option opt) { String[] values = cl.getOptionValues(opt.getOpt()); return values != null ? values : new String[0]; }