public static void printUsage() throws IOException { SnmpCommand b = new SnmpCommand("help", new HashMap<String, List<Object>>()); String help = b.help("", null, true, false); out.println(help); }
private void optionDetailList(int indentation, String prefix, StringBuffer buf, SortedMap<String, ArgumentFormat> soptions) { for (String opt : soptions.keySet()) { String o = spaces(indentation) + "-" + opt; String optSyn = help.getString("options.syn." + opt); o += tab(indentation, o.length(), 2); o += optSyn; buf.append(prefix); buf.append(o); String optDesc = help.getString("options.des." + opt); buf.append(format(getTabPosition(3), optDesc, 3, o.length())); buf.append('\n'); } }
private static String tab(int offset, int position, int tabNo) { StringBuffer buf = new StringBuffer(); if (tabs == null) { String tabString = help.getString("tabs"); String[] tabsArray = tabString.split(","); tabs = new int[tabsArray.length]; for (int i = 0; i < tabsArray.length; i++) { tabs[i] = Integer.parseInt(tabsArray[i]); } } int t = getTabPosition(tabNo); buf.append(spaces(Math.max(1, t + offset - position))); return buf.toString(); }
for (String[] COMMAND : COMMANDS) { String c = COMMAND[0]; String[] format = selectFormat(c); commands.put(c, format); options.putAll(o); buf.append(c).append(":\n"); buf.append(help("", c, false, (command != null))); buf.append('\n'); optionDetailList(getTabPosition(0), prefix, buf, options); } else { String syn = help.getString("command.syn." + prefix + command); String line = ""; if (!"".equals(syn)) { line += tab(0, 0, 0) + syn; line += (withDescription) ? "\n\n" : "\n"; if (line.length() >= getTabPosition(0)) { line += '\n'; firstLineIndent = getTabPosition(0); line += format(getTabPosition(0), des, 0, firstLineIndent); buf.append(spaces(getTabPosition(0))); buf.append(subcmds[i]).append((withDescription) ? ":\n" : ""); buf.append(help(command + ".", subcmds[i], false, withDescription));
ArgumentParser.selectCommand(args, ALL_OPTIONS, COMMANDS); if (commandSet == null) { printUsage(); System.exit(2); String helpCmd = (String) ArgumentParser.getValue(commandLineParameters, "subject", 0); SnmpCommand b = new SnmpCommand(command, commandLineParameters); String help = b.help("", helpCmd, true, true); out.println(help); String helpCmd = (String) ArgumentParser.getValue(commandLineParameters, "subject", 0); SnmpCommand b = new SnmpCommand(command, commandLineParameters); String help = b.example("", helpCmd); out.println(help); printVersion(); System.exit(0); } else { SnmpCommand browser = new SnmpCommand(command, commandLineParameters); browser.run(); System.exit(browser.returnCode); if (args.length == 0 || "help".equals(args[0])) { try { printUsage(); } catch (IOException ex1) { ex1.printStackTrace();
switch (operation) { case SNAPSHOT_DUMP: { returnCode = dumpSnapshot(); break; returnCode = listen(); break; case CVS_TABLE: case TIME_BASED_CVS_TABLE: { returnCode = table(); break; PDU response = send(); if ((pduType == PDU.TRAP) || (pduType == PDU.REPORT) || printReport(response); } else if (operation == DEFAULT) { err.println("Response received with requestID=" + "errorStatus=" + response.getErrorStatusText() + "(" + response.getErrorStatus() + ")"); printVariableBindings(response); } else { err.println("Received something strange: requestID=" + "errorStatus=" + response.getErrorStatusText() + "(" + response.getErrorStatus() + ")");
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); }
parseOIDs(args); checkTrapVariables(this.vbs);
public PDU send() throws IOException { PDU request = pduFactory.createPDU(target); for (VariableBinding vb : vbs) { request.add(vb); } PDU response = null; if ((operation == WALK) || (operation == SNAPSHOT_CREATION)) { ArrayList<VariableBinding> snapshot = null; if (operation == SNAPSHOT_CREATION) { snapshot = new ArrayList<VariableBinding>(); } walk(snmp, request, target, snapshot); if (snapshot != null) { createSnapshot(snapshot); } return null; } else { ResponseEvent responseEvent; long startTime = System.currentTimeMillis(); responseEvent = snmp.send(request, target); if (responseEvent != null) { response = responseEvent.getResponse(); err.println("Received response after " + (System.currentTimeMillis() - startTime) + " millis"); } } snmp.close(); return response; }
pduType = pduFactory.createPDU(target).getType(); assignOptions(args);