new ArgumentParser(System.getProperty("org.snmp4j.OptionFormat", "-o1[i{parameter1}] -o2[s,l]"), System.getProperty("org.snmp4j.ParameterFormat", "-param1[i] -param2[s<(udp|tcp):.*[/[0-9]+]?>{=udp:127.0.0.1/161}] "+ "+optParam1[l{=-100}] ..")); System.out.println("Option format is: "+argumentparser.getOptionFormat()); System.out.println("Parameter format is: "+argumentparser.getParameterFormat()); Map options = null; try { options = argumentparser.parse(args); System.out.println(options);
public Integer getMaxRepetitions() { Integer maxRep = (Integer) ArgumentParser.getValue(settings, oMaxRepetitions, 0); return maxRep; }
private static String parseParameterFormat(String param, ArgumentParameter ap) { int posEnd = param.indexOf('<'); posEnd = posEnd > 0 ? posEnd : param.indexOf("{"); ap.type = getType(param.substring(0, posEnd)); String defaultValue = param.substring(param.indexOf('{') + 1, param.length() - 1); int posEqual = defaultValue.indexOf('='); if (posEqual >= 0) { ap.defaultValue = defaultValue.substring(posEqual + 1); ap.name = defaultValue.substring(0, posEqual); } else { ap.name = defaultValue; } int posParamEnd = param.indexOf('>'); if (posParamEnd > 0) { posEnd = posParamEnd + 1; } param = param.substring(0, posEnd); return param; }
private static Map<?, ?> parseArgs(String[] args) { Map<?, ?> params = null; try { ArgumentParser parser = new ArgumentParser( "-f[s{=HttpJmxAgent.xml}] " + "-jmxPort[i{=8080}] " + "-rmiPort[i{=" + Registry.REGISTRY_PORT + "}]" , "" ); params = parser.parse(args); } catch (ParseException e) { throw new IllegalArgumentException(e); } return params; }
throws ParseException { ArgumentParser ap = new ArgumentParser(optionFormat, "#command[s] +following[s] .."); Map<String,List<Object>> params = ap.parse(args); String command = (String) ArgumentParser.getValue(params, "command", 0); for (String[] commandSet : commandSets) { if (commandSet[0].equals(command)) {
private String options(int indentation, String prefix, String command) { StringBuffer buf = new StringBuffer(); String[] format = selectFormat(command); if (format == null) { return ""; } ArgumentParser p = new ArgumentParser(format[0], format[1]); Map<String, ArgumentFormat> options = p.getOptionFormat(); SortedMap<String, ArgumentFormat> soptions = new TreeMap<String, ArgumentFormat>(options); optionDetailList(indentation, prefix, buf, soptions); return buf.toString(); }
try { String[] commandSet = ArgumentParser.selectCommand(args, ALL_OPTIONS, COMMANDS); if (commandSet == null) { printUsage(); new ArgumentParser(commandSet[1], commandSet[2]); commandLineParameters = parser.parse(args); String command = (String) ArgumentParser.getValue(commandLineParameters, "command", 0); if (commandLineParameters.containsKey("w")) { (Integer) ArgumentParser.getValue(commandLineParameters, "w", 0); if (width > 20) { stdoutWidth = width; new LogLevel(((String) ArgumentParser.getValue(commandLineParameters, "d", 0)).toUpperCase()); LogFactory.getLogFactory().getRootLogger().setLogLevel(level); (String) ArgumentParser.getValue(commandLineParameters, "subject", 0); SnmpCommand b = new SnmpCommand(command, commandLineParameters); String help = b.help("", helpCmd, true, true); } else if ("example".equals(command)) { String helpCmd = (String) ArgumentParser.getValue(commandLineParameters, "subject", 0); SnmpCommand b = new SnmpCommand(command, commandLineParameters); String help = b.example("", helpCmd);
public static void main(String[] args) { try { String[] commandSet = ArgumentParser.selectCommand(args, OPTIONS, COMMANDS); if (commandSet == null) { printUsage(); System.exit(2); } ArgumentParser parser = new ArgumentParser(commandSet[1], commandSet[2]); Map commandLineParameters = parser.parse(args); LogControl logcontrol = new LogControl(commandLineParameters); logcontrol.run(); } catch (ParseException pex) { System.out.println(pex.getMessage()); System.exit(1); } }
(format.getParameters().length > 0)) { int diff = (format.isParameter()) ? 1 : 0; List values = parseValues(args, i+(1-diff), format); i += Math.max(values.size() - diff, 0); if (format.isVariableLength() && addValues2Option(format.getOption(), values, options); addValues2Option(format.getOption(), null, options); for (int i=0; i<of.getParameters().length; i++) { if (of.getParameters()[i].getDefaultValue() != null) { defaults.add(parseParameterValue(of.getParameters()[i], of.getParameters()[i].getDefaultValue(), of, i)); addValues2Option(of.getOption(), defaults, options);
SampleAgent.class.getResourceAsStream("SampleAgentConfig.properties"); if (args.containsKey("cfg")) { String configFilename = (String) ArgumentParser.getValue(args, "cfg", 0); try { configInputStream = new FileInputStream(configFilename); try { tableSizeLimitsInputStream = new FileInputStream((String) ArgumentParser.getValue(args, "ts", 0)); addListenAddresses(messageDispatcher, (List<String>)args.get("address")); Collection<DHKickstartParameters> dhKickstartParameters = Collections.emptyList(); String dhKickstartInfoPath = (String)ArgumentParser.getFirstValue(args.get("dhks")); if (dhKickstartInfoPath != null) { File dhKickstartInfoFile = new File(dhKickstartInfoPath);
ap.name = "" + i; if (param.endsWith("}")) { param = parseParameterFormat(param, ap); param = param.substring(0, regexPos); if (param.endsWith("}")) { parseParameterFormat(param, ap); } else { ap.type = getType(param); ap.type = getType(param);
/** * Creates an argument parser with the specified option and parameter formats. * @param optionFormat * the option format pattern to parse (see {@link ArgumentParser}). * @param parameterFormat * the parameter format pattern to parse (see {@link ArgumentParser}). */ public ArgumentParser(String optionFormat, String parameterFormat) { this.optionFormat = parseFormat(optionFormat, false); this.parameterFormat = parseFormat(parameterFormat, true); }
protected List<Object> parseValues(String[] args, int offset, ArgumentFormat format) throws ParseException { int numParams = format.getParameters().length; List<Object> values = new ArrayList<>(numParams); for (int i = 0; (i + offset < args.length) && (i < numParams); i++) { try { values.add(parseParameterValue(format.getParameters()[i], args[i + offset], format, i + offset)); } catch (ArgumentParseException apex) { throw apex; } catch (Exception ex) { ex.printStackTrace(); int pos = i + offset; throw new ArgumentParseException(pos, args[pos], format, format.getParameters()[i]); } } return values; }
new ArgumentParser(optionFormat, "#command[s] +following[s] .."); Map params = ap.parse(args); String command = (String) ArgumentParser.getValue(params, "command", 0); for (int j=0; j<commandSets.length; j++) { if (commandSets[j][0].equals(command)) {
= new ArgumentParser(optsBuilder.toString(), paramsBuilder.toString()); params = parser.parse(args);
public static void main(String[] args) { try { String[] commandSet = ArgumentParser.selectCommand(args, OPTIONS, COMMANDS); if (commandSet == null) { printUsage(); System.exit(2); } ArgumentParser parser = new ArgumentParser(commandSet[1], commandSet[2]); Map<String,List<Object>> commandLineParameters = parser.parse(args); LogControl logcontrol = new LogControl(commandLineParameters); logcontrol.run(); } catch (ParseException pex) { System.out.println(pex.getMessage()); System.exit(1); } }
private String optionList(int indentation, String prefix, String command) { if (prefix != null) { return ""; } StringBuilder buf = new StringBuilder(); String[] format = selectFormat(command); if (format == null) { return ""; } ArgumentParser p = new ArgumentParser(format[0], format[1]); Map<String, ArgumentFormat> options = p.getOptionFormat(); SortedMap<String, ArgumentFormat> soptions = new TreeMap<>(options); for (Iterator<String> it = soptions.keySet().iterator(); it.hasNext(); ) { String opt = it.next(); buf.append("-").append(opt); if (it.hasNext()) { buf.append(", "); } } return format(indentation, buf.toString(), 0, 0); }
(format.getParameters().length > 0)) { int diff = (format.isParameter()) ? 1 : 0; List<Object> values = parseValues(args, i + (1 - diff), format); i += Math.max(values.size() - diff, 0); if (format.isVariableLength() && options.containsKey(format.getOption())) { options.get(format.getOption()).addAll(values); } else { addValues2Option(format.getOption(), values, options); addValues2Option(format.getOption(), null, options); throw new ArgumentParseException(-1, null, af, parameter); } else { defaults.add(parseParameterValue(parameter, parameter.getDefaultValue(), af, defaults.size())); addValues2Option(af.getOption(), defaults, options); defaults.add(parseParameterValue(of.getParameters()[i], of.getParameters()[i].getDefaultValue(), of, i)); throw new ArgumentParseException(-1, null, of, ((of.getParameters() != null && of.getParameters().length > 0) ? of.getParameters()[0] : null)); } else { addValues2Option(of.getOption(), defaults, options);
ap.name = ""+i; if (param.endsWith("}")) { param = parseParameterFormat(param, ap); param = param.substring(0, regexPos); if (param.endsWith("}")) { parseParameterFormat(param, ap); ap.type = getType(param); ap.type = getType(param);
/** * Creates an argument parser with the specified option and parameter formats. * * @param optionFormat * the option format pattern to parse (see {@link ArgumentParser}). * @param parameterFormat * the parameter format pattern to parse (see {@link ArgumentParser}). */ public ArgumentParser(String optionFormat, String parameterFormat) { this.optionFormat = parseFormat(optionFormat, false); this.parameterFormat = parseFormat(parameterFormat, true); }