@Override public final int parseArguments(Parameters params) throws CmdLineException { final String value = params.getParameter(0); short context; if ("all".equalsIgnoreCase(value)) { context = DiffPreferencesInfo.WHOLE_FILE_CONTEXT; } else { try { context = Short.parseShort(value, 10); if (context < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { throw new CmdLineException( owner, String.format( "\"%s\" is not a valid value for \"%s\"", value, ((NamedOptionDef) option).name())); } } setter.addValue(context); return 1; }
@SuppressWarnings("rawtypes") private static Map<String, OptionHandler> index(List<OptionHandler> in) { Map<String, OptionHandler> m = new HashMap<>(); for (OptionHandler handler : in) { if (handler.option instanceof NamedOptionDef) { NamedOptionDef def = (NamedOptionDef) handler.option; if (!def.isArgument()) { m.put(def.name(), handler); for (String alias : def.aliases()) { m.put(alias, handler); } } } } return m; }
@Override public int parseArguments(Parameters params) throws CmdLineException { String parameter = params.getParameter(0); // An empty string should be null if (parameter.isEmpty()) { setter.addValue(null); } else { setter.addValue( instantiateObject( ((NamedOptionDef) option).name(), "plugin module", Module.class, ((SoyCmdLineParser) this.owner).pluginLoader, parameter)); } return 1; }
@Override public int parseArguments(Parameters params) throws CmdLineException { String parameter = params.getParameter(0); // An empty string should be null if (parameter.isEmpty()) { setter.addValue(null); } else { setter.addValue( instantiateObject( ((NamedOptionDef) option).name(), "msg plugin", SoyMsgPlugin.class, ((SoyCmdLineParser) this.owner).pluginLoader, parameter)); } return 1; }
private static String metaVar(OptionHandler<?> handler, NamedOptionDef n) { String var = n.metaVar(); if (Strings.isNullOrEmpty(var)) { var = handler.getDefaultMetaVariable(); if (handler instanceof EnumOptionHandler) { var = var.substring(1, var.length() - 1).replace(" ", ""); } } return var; }
private void printCategoryUsage( String categoryName, final Collection<String> options, OutputStreamWriter outputStream, String prefix, String suffix) { try { if (prefix != null) { printStringLineWrapped(prefix, outputStream); } outputStream.write(boldPrefix + categoryName + ":\n" + normalPrefix); parser.printUsage( outputStream, null, new OptionHandlerFilter() { @Override public boolean select(OptionHandler optionHandler) { if (optionHandler.option instanceof NamedOptionDef) { return !optionHandler.option.hidden() && options.contains( ((NamedOptionDef) optionHandler.option).name().replaceFirst("^--", "")); } return false; } }); if (suffix != null) { printStringLineWrapped(suffix, outputStream); } } catch (IOException e) { // Ignore. } }
@Override Module parseItem(String item) { return instantiateObject( ((NamedOptionDef) option).name(), "plugin module", Module.class, ((SoyCmdLineParser) this.owner).pluginLoader, item); }
private OptionHandler<?> findOptionByName(String name) { for (OptionHandler<?> h : getOptions()) { NamedOptionDef option = (NamedOptionDef) h.option; if (name.equals(option.name())) { return h; } for (String alias : option.aliases()) { if (name.equals(alias)) { return h; } } } return null; }
private boolean isHandlerHasHisOptions(NamedOptionDef option, Set<OptionHandler<?>> present) { for (String depend : option.depends()) { if (!present.contains(findOptionHandler(depend))) return false; } return true; }
private boolean isHandlerAllowOtherOptions(NamedOptionDef option, Set<OptionHandler<?>> present) { for (String forbid : option.forbids()) { if (present.contains(findOptionHandler(forbid))) return false; } return true; }