List of usage examples for org.apache.commons.cli Option getValue
public String getValue()
null
if there is no value. From source file:org.blue.star.plugins.check_nt.java
/** * process command-line arguments //from w w w. ja v a 2s .com */ public void process_command_option(Option o) throws IllegalArgumentException { String optarg = o.getValue(); switch (o.getId()) { case 'H': /* hostname */ server_address = optarg; break; case 's': /* password */ req_password = optarg; break; case 'S': /* password file */ password_file = optarg; break; case 'p': /* port */ try { server_port = Integer.parseInt(optarg); } catch (NumberFormatException nfE) { throw new IllegalArgumentException("Port must be a valid integer."); } case 'v': if (optarg.equals("CLIENTVERSION")) vars_to_check = CHECK_CLIENTVERSION; else if (optarg.equals("CPULOAD")) vars_to_check = CHECK_CPULOAD; else if (optarg.equals("UPTIME")) vars_to_check = CHECK_UPTIME; else if (optarg.equals("USEDDISKSPACE")) vars_to_check = CHECK_USEDDISKSPACE; else if (optarg.equals("SERVICESTATE")) vars_to_check = CHECK_SERVICESTATE; else if (optarg.equals("PROCSTATE")) vars_to_check = CHECK_PROCSTATE; else if (optarg.equals("MEMUSE")) vars_to_check = CHECK_MEMUSE; else if (optarg.equals("COUNTER")) vars_to_check = CHECK_COUNTER; else if (optarg.equals("FILEAGE")) vars_to_check = CHECK_FILEAGE; else { throw new IllegalArgumentException("Unknown variable."); } break; case 'l': /* value list */ value_list = optarg; break; case 'w': /* warning threshold */ warning_value = Integer.parseInt(optarg); check_warning_value = true; break; case 'c': /* critical threshold */ critical_value = Integer.parseInt(optarg); check_critical_value = true; break; case 'd': /* Display select for services */ if (optarg.equals("SHOWALL")) show_all = true; break; case 't': /* timeout */ socket_timeout = Integer.parseInt(optarg); if (socket_timeout <= 0) { throw new IllegalArgumentException("Socket timeout must be greater than 0."); } } }
From source file:org.blue.star.plugins.check_ping.java
public void process_command_option(Option o) throws IllegalArgumentException { String optarg = o.getValue(); switch (o.getId()) { case '4': /* IPv4 only */ address_family = common_h.AF_INET; break;/*from www. ja v a 2 s. c o m*/ case '6': /* IPv6 only */ address_family = common_h.AF_INET6; // TODO Determine if IPv6 is even available. break; case 'H': /* hostname */ String[] hostnames = optarg.split(","); for (String hostname : hostnames) addresses.add(hostname); n_addresses = addresses.size(); break; case 'p': /* number of packets to send */ if (utils.is_intnonneg(optarg)) max_packets = Integer.parseInt(optarg); else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<max_packets> (%s) must be a non-negative number\n", optarg)); break; case 'n': /* no HTML */ display_html = false; break; case 'L': /* show HTML */ display_html = true; break; case 'c': crta = get_threshold_rta(optarg); cpl = get_threshold_pl(optarg); break; case 'w': wrta = get_threshold_rta(optarg); wpl = get_threshold_pl(optarg); break; case 'i': interface_name = optarg; try { network_interface = NetworkInterface.getByName(interface_name); } catch (Exception e) { throw new IllegalArgumentException("Error acquiring acces to interface " + e.getMessage()); } if (network_interface == null) { throw new IllegalArgumentException("Interface name " + interface_name + " is not available."); } break; } }
From source file:org.blue.star.plugins.check_salesforce_api.java
public void process_command_option(Option o) throws IllegalArgumentException { String argValue = o.getValue(); switch (o.getId()) { case 'u': this.user = argValue; break;//from w w w . ja v a 2 s . c om case 'p': this.pass = argValue; break; case 'w': this.url = argValue; break; } }
From source file:org.blue.star.plugins.check_salesforce_schema.java
public void process_command_option(Option o) throws IllegalArgumentException { String argValue = o.getValue(); switch (o.getId()) { case 'u': this.user = argValue; break;//from ww w .j a va 2 s .c o m case 'p': this.pass = argValue; break; case 'w': this.url = argValue; break; case 'k': this.keepBase = true; break; } }
From source file:org.blue.star.plugins.send_mail.java
public void process_command_option(Option o) throws IllegalArgumentException { String optarg = o.getValue(); switch (o.getId()) { case 'M': this.message = optarg; break;//from w ww . j a v a 2 s .com case 'S': this.subject = optarg; break; case 'F': this.from = optarg; break; case 'T': this.to = optarg; break; case 's': this.smtpServer = optarg; break; case 'U': this.smtpUser = optarg; break; case 'P': this.smtpPass = optarg; break; case 'A': this.smtpAuth = true; break; case 'L': this.ssl = true; break; } }
From source file:org.Cherry.Main.Application.java
void process() { final Option httpPortOption = OptionBuilder.withArgName(CmdLineArg.httpPort.name()).hasArg() .withDescription("port to listen on [8080]").create(CmdLineArg.httpPort.name()), configFileOption = OptionBuilder.withArgName(CmdLineArg.configFile.name()).hasArg() .withDescription("configuration file to use").create(CmdLineArg.configFile.name()), controllerNamespaces = OptionBuilder.withArgName(CmdLineArg.controllerNamespaces.name()).hasArg() .withDescription("Controller namespace declarations") .create(CmdLineArg.controllerNamespaces.name()); final Options options = new Options(); options.addOption(configFileOption); options.addOption(httpPortOption);/*from w w w . j a v a2 s . co m*/ options.addOption(controllerNamespaces); final CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, INSTANCE_ARGUMENTS); } catch (final ParseException e) { error(e, ""); throw new IllegalArgumentException(e); } final Option[] processedOptions = commandLine.getOptions(); if (null != processedOptions && 0 < processedOptions.length) { final Map<CmdLineArg, Object> optionMap = new HashMap<CmdLineArg, Object>(processedOptions.length); CmdLineArg cmdLineArg; Boolean configFileDeclared = false; for (final Option option : processedOptions) { cmdLineArg = CmdLineArg.valueOf(option.getArgName()); switch (cmdLineArg) { case configFile: if (configFileDeclared) throw new IllegalArgumentException( "Duplicated declaration for argument [" + cmdLineArg + "]"); optionMap.put(cmdLineArg, option.getValue()); configFileDeclared = true; break; case httpPort: if (configFileDeclared) { warn("{}", "Configuration file foumd, all other options - including [" + cmdLineArg + "] will be ignored!"); continue; } if (optionMap.containsKey(cmdLineArg)) throw new IllegalArgumentException( "Duplicated declaration for argument [" + cmdLineArg + "]"); optionMap.put(cmdLineArg, option.getValue()); break; case controllerNamespaces: if (configFileDeclared) { warn("{}", "Configuration file foumd, all other options - including [" + cmdLineArg + "] will be ignored!"); continue; } if (optionMap.containsKey(cmdLineArg)) throw new IllegalArgumentException( "Duplicated declaration for argument [" + cmdLineArg + "]"); optionMap.put(cmdLineArg, option.getValue()); break; default: warn("Will ignore [{}]=[{}]", cmdLineArg, option.getValue()); } } final File cfgFile = new File((String) optionMap.get(CmdLineArg.configFile)); if (!cfgFile.exists() || cfgFile.isDirectory()) throw new IllegalArgumentException( "Missing configuration file [" + cfgFile.getPath() + "] or it is a directory!"); FileInputStream fis = null; Configuration configuration; try { fis = new FileInputStream(cfgFile); configuration = getObjectMapperService().readValue(fis, Configuration.class); } catch (final IOException e) { error(e, ""); throw new IllegalArgumentException(e); } finally { try { fis.close(); } catch (final IOException e) { error(e, ""); } } debug("{}", configuration); getApplicationRepositoryService().put(ApplicationKey.Configuration, new ApplicationEntry<Configuration>(configuration)); } }
From source file:org.commonvox.hbase_column_manager.UtilityRunner.java
private void logParmInfo(CommandLine commandLine) { StringBuilder parmInfo = new StringBuilder(this.getClass().getSimpleName() + " has been invoked with the following <option=argument> combinations:"); for (Option option : commandLine.getOptions()) { parmInfo.append(" <").append(option.getLongOpt()) .append(option.getValue() == null ? "" : ("=" + option.getValue())).append(">"); }/* w w w .j ava 2s . c o m*/ LOG.info(parmInfo); }
From source file:org.fcrepo.importexport.ArgParser.java
/** * This method writes the configuration file to disk. The current * implementation omits the user/password information. * @param args to be persisted// w ww . ja v a2 s . c om */ private void saveConfig(final CommandLine cmd) { final File configFile = new File(System.getProperty("java.io.tmpdir"), CONFIG_FILE_NAME); // Leave existing config file alone if (configFile.exists()) { logger.info("Configuration file exists, new file will NOT be created: {}", configFile.getPath()); return; } // Write config to file try (final BufferedWriter configWriter = new BufferedWriter(new FileWriter(configFile));) { for (Option option : cmd.getOptions()) { // write out all but the username/password if (!option.getOpt().equals("u")) { configWriter.write("-" + option.getOpt()); configWriter.newLine(); if (option.getValue() != null) { configWriter.write(option.getValue()); configWriter.newLine(); } } } logger.info("Saved configuration to: {}", configFile.getPath()); } catch (IOException e) { throw new RuntimeException("Unable to write configuration file due to: " + e.getMessage(), e); } }
From source file:org.jf.baksmali.main.java
/** * Run!//from w w w. jav a 2 s. c o m */ public static void main(String[] args) throws IOException { Locale locale = new Locale("en", "US"); Locale.setDefault(locale); CommandLineParser parser = new PosixParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException ex) { usage(); return; } baksmaliOptions options = new baksmaliOptions(); boolean disassemble = true; boolean doDump = false; String dumpFileName = null; boolean setBootClassPath = false; String[] remainingArgs = commandLine.getArgs(); Option[] clOptions = commandLine.getOptions(); for (int i = 0; i < clOptions.length; i++) { Option option = clOptions[i]; String opt = option.getOpt(); switch (opt.charAt(0)) { case 'v': version(); return; case '?': while (++i < clOptions.length) { if (clOptions[i].getOpt().charAt(0) == '?') { usage(true); return; } } usage(false); return; case 'o': options.outputDirectory = commandLine.getOptionValue("o"); break; case 'p': options.noParameterRegisters = true; break; case 'l': options.useLocalsDirective = true; break; case 's': options.useSequentialLabels = true; break; case 'b': options.outputDebugInfo = false; break; case 'd': options.bootClassPathDirs.add(option.getValue()); break; case 'f': options.addCodeOffsets = true; break; case 'r': String[] values = commandLine.getOptionValues('r'); int registerInfo = 0; if (values == null || values.length == 0) { registerInfo = baksmaliOptions.ARGS | baksmaliOptions.DEST; } else { for (String value : values) { if (value.equalsIgnoreCase("ALL")) { registerInfo |= baksmaliOptions.ALL; } else if (value.equalsIgnoreCase("ALLPRE")) { registerInfo |= baksmaliOptions.ALLPRE; } else if (value.equalsIgnoreCase("ALLPOST")) { registerInfo |= baksmaliOptions.ALLPOST; } else if (value.equalsIgnoreCase("ARGS")) { registerInfo |= baksmaliOptions.ARGS; } else if (value.equalsIgnoreCase("DEST")) { registerInfo |= baksmaliOptions.DEST; } else if (value.equalsIgnoreCase("MERGE")) { registerInfo |= baksmaliOptions.MERGE; } else if (value.equalsIgnoreCase("FULLMERGE")) { registerInfo |= baksmaliOptions.FULLMERGE; } else { usage(); return; } } if ((registerInfo & baksmaliOptions.FULLMERGE) != 0) { registerInfo &= ~baksmaliOptions.MERGE; } } options.registerInfo = registerInfo; break; case 'c': String bcp = commandLine.getOptionValue("c"); if (bcp != null && bcp.charAt(0) == ':') { options.addExtraClassPath(bcp); } else { setBootClassPath = true; options.setBootClassPath(bcp); } break; case 'x': options.deodex = true; break; case 'm': options.noAccessorComments = true; break; case 'a': options.apiLevel = Integer.parseInt(commandLine.getOptionValue("a")); break; case 'j': options.jobs = Integer.parseInt(commandLine.getOptionValue("j")); break; case 'i': String rif = commandLine.getOptionValue("i"); options.setResourceIdFiles(rif); break; case 'N': disassemble = false; break; case 'D': doDump = true; dumpFileName = commandLine.getOptionValue("D"); break; case 'I': options.ignoreErrors = true; break; case 'T': options.inlineResolver = new CustomInlineMethodResolver(options.classPath, new File(commandLine.getOptionValue("T"))); break; default: assert false; } } if (remainingArgs.length != 1) { usage(); return; } if (options.jobs <= 0) { options.jobs = Runtime.getRuntime().availableProcessors(); if (options.jobs > 6) { options.jobs = 6; } } if (options.apiLevel >= 17) { options.checkPackagePrivateAccess = true; } String inputDexFileName = remainingArgs[0]; File dexFileFile = new File(inputDexFileName); if (!dexFileFile.exists()) { System.err.println("Can't find the file " + inputDexFileName); System.exit(1); } //Read in and parse the dex file DexBackedDexFile dexFile = DexFileFactory.loadDexFile(dexFileFile, options.apiLevel); if (dexFile.isOdexFile()) { if (!options.deodex) { System.err.println("Warning: You are disassembling an odex file without deodexing it. You"); System.err.println("won't be able to re-assemble the results unless you deodex it with the -x"); System.err.println("option"); options.allowOdex = true; } } else { options.deodex = false; } if (!setBootClassPath && (options.deodex || options.registerInfo != 0)) { if (dexFile instanceof DexBackedOdexFile) { options.bootClassPathEntries = ((DexBackedOdexFile) dexFile).getDependencies(); } else { options.bootClassPathEntries = getDefaultBootClassPathForApi(options.apiLevel); } } if (options.inlineResolver == null && dexFile instanceof DexBackedOdexFile) { options.inlineResolver = InlineMethodResolver .createInlineMethodResolver(((DexBackedOdexFile) dexFile).getOdexVersion()); } boolean errorOccurred = false; if (disassemble) { errorOccurred = !baksmali.disassembleDexFile(dexFile, options); } if (doDump) { if (dumpFileName == null) { dumpFileName = commandLine.getOptionValue(inputDexFileName + ".dump"); } dump.dump(dexFile, dumpFileName, options.apiLevel); } if (errorOccurred) { System.exit(1); } }
From source file:org.jruyi.cli.Main.java
private boolean processCommandLines(String[] args) throws Throwable { Options options = new Options(); options.addOption("?", "help", false, null); options.addOption("h", "host", true, null); options.addOption("p", "port", true, null); options.addOption("t", "timeout", true, null); options.addOption("f", "file", false, null); CommandLine line = new PosixParser().parse(options, args); Option[] opts = line.getOptions(); for (Option option : opts) { String opt = option.getOpt(); if (opt.equals("?")) { printHelp();/* w w w . ja va 2 s. c o m*/ return false; } else if (opt.equals("h")) { String v = option.getValue(); if (v != null) RuyiCli.INST.host(v); } else if (opt.equals("p")) { String v = option.getValue(); if (v != null) RuyiCli.INST.port(Integer.parseInt(v)); } else if (opt.equals("t")) { String v = option.getValue(); if (v != null) RuyiCli.INST.timeout(Integer.parseInt(v) * 1000); } else if (opt.equals("f")) { args = line.getArgs(); if (args == null || args.length < 1) System.out.println("Please specify SCRIPT."); else RuyiCli.INST.run(args); return false; } else throw new Exception("Unknown option: " + option); } args = line.getArgs(); if (args == null || args.length < 1) return true; String command = args[0]; int n = args.length; if (n > 1) { StringBuilder builder = new StringBuilder(256); builder.append(command); for (int i = 1; i < n; ++i) builder.append(' ').append(args[i]); command = builder.toString(); } RuyiCli.INST.run(command); return false; }