List of usage examples for org.apache.commons.cli Option setOptionalArg
public void setOptionalArg(boolean optionalArg)
From source file:info.mikaelsvensson.devtools.analysis.shared.CommandLineUtil.java
public List<Option> getOptions(Object owner) throws IllegalAccessException { List<Option> options = new ArrayList<Option>(); Class<?> cls = owner.getClass(); do {/*from www.j ava 2 s .c o m*/ CliOptions cliOptions = cls.getAnnotation(CliOptions.class); if (cliOptions != null) { for (CliOptionConfig config : cliOptions.opts()) { if (config != null) { Option option = new Option(config.name(), config.description()); if (config.longName().length() > 0) { option.setLongOpt(config.longName()); } if (config.numArgs() == OPTIONAL) { option.setOptionalArg(true); } else { option.setArgs(config.numArgs()); } option.setArgName(config.argsDescription()); option.setRequired(config.required()); option.setValueSeparator(config.separator()); options.add(option); } } } } while ((cls = cls.getSuperclass()) != null); return options; }
From source file:edu.ksu.cis.indus.tools.slicer.SliceXMLizerCLI.java
/** * Parses the command line argument./*from www . j a v a 2 s . c o m*/ * * @param args contains the command line arguments. * @param xmlizer used to xmlize the slice. * @pre args != null and xmlizer != null */ private static void parseCommandLine(final String[] args, final SliceXMLizerCLI xmlizer) { // create options final Options _options = new Options(); Option _o = new Option("c", "config-file", true, "The configuration file to use. If unspecified, uses default configuration file."); _o.setArgs(1); _o.setArgName("config-file"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("a", "active-config", true, "The alternate configuration to use instead of the one specified in the configuration."); _o.setArgs(1); _o.setArgName("config"); _o.setLongOpt("active-config"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("o", "output-dir", true, "The output directory to dump the generated info. If unspecified, picks a temporary directory."); _o.setArgs(1); _o.setArgName("path"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("g", "gui-config", false, "Display gui for configuration."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("p", "soot-classpath", true, "Prepend this to soot class path."); _o.setArgs(1); _o.setArgName("classpath"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("e", "exception-preserving-slice", true, "Generate slice that preserves every throw statement in " + "the application class. Comma-separated combination of optional arguments: inAppOnly - preserve throw " + "statements in application classes only, separateSlices - generated a different slice for each throw " + "statement. **This option should not be combined with -r**"); _o.setArgs(1); _o.setOptionalArg(true); _o.setArgName("applClassOnly"); _options.addOption(_o); _o = new Option(" ", "detailedStats", false, "Display detailed stats."); _o.setOptionalArg(false); _o = new Option("h", "help", false, "Display message."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("i", "output-xml-jimple-before-res", false, "Output xml representation of the jimple BEFORE residualization."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("j", "output-xml-jimple-after-res", false, "Output xml representation of the jimple AFTER residualization. This only works with -r option."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("I", "output-jimple-before-res", false, "Output jimple BEFORE residualization."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("J", "output-jimple-after-res", false, "Output jimple AFTER residualization. This only works with -r option."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("s", "criteria-spec-file", true, "Use the slice criteria specified in this file."); _o.setArgs(1); _o.setArgName("crit-spec-file"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("sa", "Perform scoped analysis (as opposed merely performing scoped slicing)"); _options.addOption(_o); _o = new Option("S", "slice-scope-spec-file", true, "Use the scope specified in this file."); _o.setArgs(1); _o.setArgName("slice-scope-spec-file"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("r", "residualize", true, "Residualize after slicing. This will also dump the class files for the residualized classes. Provide the " + "name of the file as an optional argument to optimize the slice (via transformation) for space. The file should" + "contain the FQN of classes (1 per line) to be retained during optimization."); _o.setOptionalArg(true); _options.addOption(_o); _o = new Option("x", "output-slice-xml", false, "Output xml representation of the slice."); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("l", true, "Generate criteria based on line number based criteria spec file. The format is " + "<class FQN>=<comma-separated list of line numbers from the class containing Java file>."); _o.setArgs(1); _o.setArgName("line-based-criteria-spec-file"); _o.setOptionalArg(false); _options.addOption(_o); CommandLine _cl = null; // parse the arguments Exception _exception = null; try { _cl = (new BasicParser()).parse(_options, args); } catch (ParseException _e) { _exception = _e; } if (_exception != null || _cl.hasOption("h")) { printUsage(_options); if (_exception != null) { LOGGER.error("Incorrect command line. Aborting.", _exception); System.exit(1); } else { System.exit(0); } } xmlizer.setConfiguration(processCommandLineForConfiguration(_cl)); setupOutputOptions(_cl, xmlizer); if (_cl.hasOption('p')) { xmlizer.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('a')) { xmlizer.setConfigName(_cl.getOptionValue('a')); } if (_cl.hasOption('g')) { xmlizer.showGUI(); } if (_cl.hasOption('s')) { xmlizer.setSliceCriteriaSpecFile(_cl.getOptionValue('s')); } if (_cl.hasOption('r')) { xmlizer.setResidulization(true); final String _optionValue = _cl.getOptionValue('r'); if (_optionValue != null) { xmlizer.extractExclusionListForCompaction(_optionValue); } } if (_cl.hasOption('S')) { sliceScope = xmlizer.setScopeSpecFile(_cl.getOptionValue('S')); if (_cl.hasOption("sa")) { xmlizer.setScopeSpecFile(_cl.getOptionValue('S')); } else { xmlizer.setScopeSpecFile(null); } } if (_cl.hasOption('l')) { xmlizer.setLineBasedCriteriaSpecFile(_cl.getOptionValue('l')); } xmlizer.preserveThrowStatements = _cl.hasOption('e'); if (xmlizer.preserveThrowStatements) { xmlizer.parseThrowStmtTreatmentOptions(_cl.getOptionValue('e')); } if (xmlizer.generateSeparateSlicesForEachThrowStmt && xmlizer.residualize) { throw new IllegalArgumentException( "Residualization (-r) cannot be combined multiple slice generation mode (-e separateSlices)."); } xmlizer.detailedStats = _cl.hasOption("detailedStats"); xmlizer.shouldWriteSliceXML = _cl.hasOption('x'); final List<String> _result = _cl.getArgList(); if (_result.isEmpty()) { LOGGER.error( "Please specify atleast one class that contains an entry method into the system to be sliced."); System.exit(1); } xmlizer.setClassNames(_result); }
From source file:com.net2plan.cli.CLINet2Plan.java
/** * Default constructor.// w w w.ja va2s. c o m * * @param args Command-line arguments */ public CLINet2Plan(String args[]) { try { SystemUtils.configureEnvironment(CLINet2Plan.class, UserInterface.CLI); for (Class<? extends Plugin> plugin : PluginSystem.getPlugins(ICLIModule.class)) { try { ICLIModule instance = ((Class<? extends ICLIModule>) plugin).newInstance(); modes.put(instance.getModeName(), instance.getClass()); } catch (NoClassDefFoundError e) { e.printStackTrace(); throw new Net2PlanException("Class " + e.getMessage() + " cannot be found. A dependence for " + plugin.getSimpleName() + " is missing?"); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); throw new RuntimeException(e); } } Option helpOption = new Option("help", true, "Show the complete help information. 'modeName' is optional"); helpOption.setArgName("modeName"); helpOption.setOptionalArg(true); Option modeOption = new Option("mode", true, "Mode: " + StringUtils.join(StringUtils.toArray(modes.keySet()), ", ")); modeOption.setArgName("modeName"); modeOption.setOptionalArg(true); OptionGroup group = new OptionGroup(); group.addOption(modeOption); group.addOption(helpOption); options.addOptionGroup(group); CommandLineParser parser = new CommandLineParser(); CommandLine cli = parser.parse(options, args); if (cli.hasOption("help")) { String mode = cli.getOptionValue("help"); System.out.println(mode == null ? getCompleteHelp() : getModeHelp(mode)); } else if (!cli.hasOption("mode")) { System.out.println(getMainHelp()); } else { String mode = cli.getOptionValue("mode"); if (modes.containsKey(mode)) { ICLIModule modeInstance = modes.get(mode).newInstance(); try { modeInstance.executeFromCommandLine(args); } catch (Net2PlanException | JOMException ex) { if (ErrorHandling.isDebugEnabled()) ErrorHandling.printStackTrace(ex); System.out.println("Execution stopped"); System.out.println(); System.out.println(ex.getMessage()); } catch (ParseException ex) { System.out.println("Bad syntax: " + ex.getMessage()); System.out.println(); System.out.println(getModeHelp(mode)); } catch (Throwable ex) { Throwable ex1 = ErrorHandling.getInternalThrowable(ex); if (ex1 instanceof Net2PlanException || ex1 instanceof JOMException) { if (ErrorHandling.isDebugEnabled()) ErrorHandling.printStackTrace(ex); System.out.println("Execution stopped"); System.out.println(); System.out.println(ex1.getMessage()); } else if (ex1 instanceof ParseException) { System.out.println("Bad syntax: " + ex1.getMessage()); System.out.println(); System.out.println(getModeHelp(mode)); } else { System.out.println("Execution stopped. An unexpected error happened"); System.out.println(); ErrorHandling.printStackTrace(ex1); } } } else { throw new IllegalModeException("Bad mode - " + mode); } } } catch (IllegalModeException e) { System.out.println(e.getMessage()); System.out.println(); System.out.println(getMainHelp()); } catch (ParseException e) { System.out.println("Bad syntax: " + e.getMessage()); System.out.println(); System.out.println(getMainHelp()); } catch (Net2PlanException e) { if (ErrorHandling.isDebugEnabled()) ErrorHandling.printStackTrace(e); System.out.println(e.getMessage()); } catch (Throwable e) { ErrorHandling.printStackTrace(e); } }
From source file:com.cyberway.issue.crawler.CommandLineParser.java
/** * Constructor./*from ww w .j a v a2 s .c om*/ * * @param args Command-line arguments to process. * @param out PrintStream to write on. * @param version Heritrix version * * @throws ParseException Failied parse of command line. */ public CommandLineParser(String[] args, PrintWriter out, String version) throws ParseException { super(); this.out = out; this.version = version; this.options = new Options(); this.options.addOption(new Option("h", "help", false, "Prints this message and exits.")); this.options.addOption(new Option("b", "bind", true, "Comma-separated list of IP addresses or hostnames for web server " + "to listen on. Set to / to listen on all available\nnetwork " + "interfaces. Default is 127.0.0.1.")); this.options.addOption(new Option("p", "port", true, "Port to run web user interface on. Default: 8080.")); this.options.addOption(new Option("a", "admin", true, "Login and password for web user interface administration. " + "Required (unless passed via the 'heritrix.cmdline.admin'\n" + "system property). Pass value of the form 'LOGIN:PASSWORD'.")); this.options .addOption(new Option("r", "run", false, "Put heritrix into run mode. If ORDER.XML begin crawl.")); this.options.addOption( new Option("n", "nowui", false, "Put heritrix into run mode and begin crawl using ORDER.XML." + " Do not put up web user interface.")); Option option = new Option("s", "selftest", true, "Run the integrated selftests. Pass test name to test it only" + " (Case sensitive: E.g. pass 'Charset' to run charset selftest)."); option.setOptionalArg(true); this.options.addOption(option); PosixParser parser = new PosixParser(); try { this.commandLine = parser.parse(this.options, args, false); } catch (UnrecognizedOptionException e) { usage(e.getMessage(), 1); } }
From source file:edu.vt.middleware.crypt.KeyStoreCli.java
/** {@inheritDoc} */ protected void initOptions() { super.initOptions(); final Option keystore = new Option(OPT_STORE, true, "keystore file"); keystore.setArgName("filepath"); keystore.setOptionalArg(false); final Option pass = new Option(OPT_PASS, true, "keystore password"); pass.setArgName("password"); pass.setOptionalArg(false);// ww w.j ava 2s. co m final Option type = new Option(OPT_TYPE, true, "keystore type, e.g. BKS (default), JKS"); type.setArgName("name"); type.setOptionalArg(false); final Option alias = new Option(OPT_ALIAS, true, "alias assigned to imported item or alias of item to export"); alias.setArgName("name"); alias.setOptionalArg(false); final Option cert = new Option(OPT_CERT, true, "X.509 certificate file; " + "encoding determined by file extension (der|pem)"); cert.setArgName("filepath"); cert.setOptionalArg(false); final Option key = new Option(OPT_KEY, true, "DER-encoded PKCS#8 or PEM-encoded SSLeay private key; " + "encoding determined by file extension (der|pem)"); key.setArgName("filepath"); key.setOptionalArg(false); final Option keyalg = new Option(OPT_KEYALG, true, "private key algorithm name; assumes RSA if not specified"); keyalg.setArgName("algorithm"); keyalg.setOptionalArg(false); options.addOption(keystore); options.addOption(pass); options.addOption(type); options.addOption(alias); options.addOption(cert); options.addOption(key); options.addOption(keyalg); options.addOption(new Option(OPT_LIST, "list keystore contents")); options.addOption(new Option(OPT_IMPORT, "import cert or cert/key pair")); options.addOption(new Option(OPT_EXPORT, "export cert or cert/key pair")); }
From source file:com.google.caja.plugin.Config.java
private Option defineBooleanOption(String shortFlag, String longFlag, String help) { Option opt = new Option(shortFlag, longFlag, false, help); opt.setOptionalArg(true); options.addOption(opt);//from w w w.j av a 2 s. c o m return opt; }
From source file:com.google.caja.plugin.Config.java
private Option defineOption(String shortFlag, String longFlag, String help, boolean optional) { Option opt = new Option(shortFlag, longFlag, /* hasArg: */ true, help); opt.setOptionalArg(optional); options.addOption(opt);/*from w ww . j a v a2s . co m*/ return opt; }
From source file:net.nharyes.drivecopy.Main.java
private void composeOptions() { // file option Option file = OptionBuilder.create('f'); file.setLongOpt("file"); file.setArgs(1);/* w w w . j a v a 2 s . c om*/ file.setArgName("path"); file.setDescription("where path is the file to upload/download/replace."); // directory option Option directory = OptionBuilder.create('d'); directory.setLongOpt("directory"); directory.setArgs(1); directory.setArgName("path"); directory.setDescription( "where path is the local directory to upload/download/replace (it will be archived into a single remote file)."); // file and directory group OptionGroup group = new OptionGroup(); group.addOption(file); group.addOption(directory); group.setRequired(true); options.addOptionGroup(group); // compression level option Option level = OptionBuilder.create('l'); level.setLongOpt("level"); level.setArgs(1); level.setArgName("num"); level.setOptionalArg(true); level.setType(Integer.class); level.setDescription( "where num is the compression level from 0 to 9. Used when uploading/replacing directories. The default value is 0."); options.addOption(level); // delete option Option delete = OptionBuilder.create('D'); delete.setLongOpt("delete"); delete.setOptionalArg(true); delete.setType(Boolean.class); delete.setDescription("delete local file/directory after remote entry uploaded/replaced."); options.addOption(delete); // log option Option log = OptionBuilder.create('L'); log.setLongOpt("log"); log.setArgs(1); log.setArgName("file"); log.setType(String.class); log.setDescription("where file is the log file to write"); options.addOption(log); // MIME type option Option mimeType = OptionBuilder.create('m'); mimeType.setLongOpt("mimetype"); mimeType.setArgs(1); mimeType.setArgName("type"); mimeType.setType(String.class); mimeType.setDescription( "where type is the MIME type string to set for the remote entry. The default values are 'application/octet-stream' for files and 'application/zip' for compressed directories."); options.addOption(mimeType); // skip revision option Option skipRevision = OptionBuilder.create('s'); skipRevision.setLongOpt("skiprevision"); skipRevision.setOptionalArg(true); skipRevision.setType(Boolean.class); skipRevision.setDescription("do not create a new revision when replacing remote entry."); options.addOption(skipRevision); // check MD5 option Option checkMd5 = OptionBuilder.create('c'); checkMd5.setLongOpt("checkmd5"); checkMd5.setOptionalArg(true); checkMd5.setType(Boolean.class); checkMd5.setDescription( "compare uploaded/downloaded local file MD5 summary with the one of the remote entry."); options.addOption(checkMd5); // check force creation option Option forceCreation = OptionBuilder.create('F'); forceCreation.setLongOpt("force"); forceCreation.setOptionalArg(true); forceCreation.setType(Boolean.class); forceCreation.setDescription( "forces the creation of the remote entry when replace is selected and the entry doesn't exist."); options.addOption(forceCreation); // settings file option Option settings = OptionBuilder.create('C'); settings.setLongOpt("configuration"); settings.setArgs(1); settings.setArgName("path"); settings.setType(String.class); settings.setDescription(String.format( "where path is the path of the configuration file. The default value is '%s' in the same directory.", CONFIGURATION_FILE)); options.addOption(settings); // create folders tree option Option tree = OptionBuilder.create('t'); tree.setLongOpt("tree"); tree.setOptionalArg(true); tree.setType(Boolean.class); tree.setDescription("create remote folders tree if one or more remote folders are not found."); options.addOption(tree); }
From source file:de.nrw.hbz.regal.sync.Syncer.java
/** * @param ingester// w w w .ja v a 2s . c o m * the ingester is used to pass data to the archive * @param downloader * the downloader is used to download data from a foreign system * @param builder * the builder assembles DigitalEntities from the downloaded data * and passes it to the ingester. */ public Syncer(IngestInterface ingester, DownloaderInterface downloader, DigitalEntityBuilderInterface builder) { this.ingester = ingester; this.downloader = downloader; this.builder = builder; options = new Options(); options.addOption("?", "help", false, "Print usage information"); options.addOption("m", "mode", true, "Specify mode: \n " + "INIT: All PIDs will be downloaded. All pids will be updated or created.\n" + "SYNC: Modified or new PIDs will be downloaded and updated or created\n " + "CONT: All PIDs that aren't already downloaded will be downloaded and created or updated\n" + "UPDT: In accordance to the timestamp all modified PIDs will be reingested" + "PIDL: Use this mode in combination with -list to provide a file with a newline separated pidlist" + "DELE: Use this mode in combination with -list to provide a file with a newline separated pidlist"); options.addOption("u", "user", true, "Specify username"); options.addOption("p", "password", true, "Specify password"); options.addOption("dtl", "dtl", true, "Specify digitool url"); options.addOption("cache", "cache", true, "Specify local directory"); options.addOption("oai", "oai", true, "Specify the OAI-PMH endpoint"); Option setOption = new Option("set", "set", true, "Specify an OAI setSpec"); setOption.setValueSeparator(','); setOption.setRequired(false); setOption.setOptionalArg(true); options.addOption(setOption); options.addOption("timestamp", "timestamp", true, "Specify a local file e.g. .oaitimestamp"); options.addOption("fedoraBase", "fedoraBase", true, "The Fedora Baseurl"); options.addOption("host", "host", true, "The Fedora Baseurl"); options.addOption("namespace", "namespace", true, "The namespace to operate on."); options.addOption("list", "list", true, "Path to a file with a newline separated pidlist. Only needed in combination with mode PIDL and DELE."); options.addOption("keystoreLocation", "keystoreLocation", true, "Specify a keystore for ssl"); options.addOption("keystorePassword", "keystorePassword", true, "Specify a keystore password for ssl"); }
From source file:edu.vt.middleware.crypt.symmetric.SymmetricCli.java
/** {@inheritDoc} */ protected void initOptions() { super.initOptions(); final Option mode = new Option(OPT_MODE, true, "cipher mode, e.g. CBC"); mode.setArgName("name"); mode.setOptionalArg(false); final Option padding = new Option(OPT_PADDING, true, "cipher padding strategy, e.g. PKCS5Padding"); padding.setArgName("padding"); padding.setOptionalArg(false);//from ww w . j a v a 2s . com final Option key = new Option(OPT_KEY, true, "encryption/decryption key"); key.setArgName("filepath"); key.setOptionalArg(false); final Option keySize = new Option(OPT_KEYSIZE, true, "key size in bits; only needed if -key option is not specified"); keySize.setArgName("bits"); keySize.setOptionalArg(false); final Option iv = new Option(OPT_IV, true, "initialization vectory in hex"); iv.setArgName("hex_iv"); iv.setOptionalArg(false); final Option pbe = new Option(OPT_PBE, true, "generate PBE key from password/phrase; uses pkcs5s2 by default"); pbe.setArgName("password"); pbe.setOptionalArg(false); final Option pbeScheme = new Option(OPT_SCHEME, true, "PBE key generation mode; one of pkcs5s1, pkcs5s2, openssl, pkcs12"); pbeScheme.setArgName("name"); pbeScheme.setOptionalArg(false); final Option pbeDigest = new Option(OPT_DIGEST, true, "digest algorithm to use with PBE mode pkcs5s1 or pkcs12"); pbeDigest.setArgName("name"); pbeDigest.setOptionalArg(false); final Option salt = new Option(OPT_SALT, true, "salt for PBE key generation in hex"); salt.setArgName("hex_salt"); salt.setOptionalArg(false); final Option iterations = new Option(OPT_ITERATIONS, true, "iteration count for PBE key generation"); salt.setArgName("count"); salt.setOptionalArg(false); final Option genKey = new Option(OPT_GENKEY, true, "generate key of given size written to path specified by -out option"); genKey.setArgName("bitsize"); genKey.setOptionalArg(false); options.addOption(mode); options.addOption(padding); options.addOption(key); options.addOption(keySize); options.addOption(iv); options.addOption(pbe); options.addOption(pbeScheme); options.addOption(pbeDigest); options.addOption(salt); options.addOption(iterations); options.addOption(genKey); options.addOption(new Option(OPT_ENCRYPT, "perform encryption")); options.addOption(new Option(OPT_DECRYPT, "perform decryption")); }