List of usage examples for org.apache.commons.cli Option setLongOpt
public void setLongOpt(String longOpt)
From source file:com.soulgalore.crawler.run.CrawlToFile.java
/** * Get the options./* w w w . ja v a2 s. c o m*/ * * @return the specific CrawlToCsv options */ @Override protected Options getOptions() { final Options options = super.getOptions(); final Option filenameOption = new Option("f", "the name of the output file, default name is " + DEFAULT_FILENAME + " [optional]"); filenameOption.setArgName("FILENAME"); filenameOption.setLongOpt("filename"); filenameOption.setRequired(false); filenameOption.setArgs(1); options.addOption(filenameOption); final Option errorFilenameOption = new Option("ef", "the name of the error output file, default name is " + DEFAULT_ERROR_FILENAME + " [optional]"); errorFilenameOption.setArgName("ERRORFILENAME"); errorFilenameOption.setLongOpt("errorfilename"); errorFilenameOption.setRequired(false); errorFilenameOption.setArgs(1); options.addOption(errorFilenameOption); final Option verboseOption = new Option("ve", "verbose logging, default is false [optional]"); verboseOption.setArgName("VERBOSE"); verboseOption.setLongOpt("verbose"); verboseOption.setRequired(false); verboseOption.setArgs(1); verboseOption.setType(Boolean.class); options.addOption(verboseOption); return options; }
From source file:com.googlecode.dex2jar.tools.BaseCmd.java
protected void initOptionFromClass(Class<?> clz) { if (clz == null) { return;// ww w . j av a2 s . c o m } else { initOptionFromClass(clz.getSuperclass()); } Field[] fs = clz.getDeclaredFields(); for (Field f : fs) { Opt opt = f.getAnnotation(Opt.class); if (opt != null) { f.setAccessible(true); if (!opt.hasArg()) { Class<?> type = f.getType(); if (!type.equals(boolean.class)) { throw new RuntimeException( "the type of " + f + " must be boolean, as it is declared as no args"); } boolean b; try { b = (Boolean) f.get(this); } catch (Exception e) { throw new RuntimeException(e); } if (b) { throw new RuntimeException( "the value of " + f + " must be false, as it is declared as no args"); } } Option option = new Option(opt.opt(), opt.hasArg(), opt.description()); option.setRequired(opt.required()); if (!"".equals(opt.longOpt())) { option.setLongOpt(opt.longOpt()); } if (!"".equals(opt.argName())) { option.setArgName(opt.argName()); } options.addOption(option); map.put(opt.opt(), f); } } }
From source file:net.nharyes.drivecopy.Main.java
private void composeOptions() { // file option Option file = OptionBuilder.create('f'); file.setLongOpt("file"); file.setArgs(1);/* ww w .j a v a 2 s .c o m*/ 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:in.hatimi.nosh.support.CmdLineManager.java
private Option optionFromField(Field field) { CmdLineOption clo = field.getAnnotation(CmdLineOption.class); if (clo == null) { return null; }/* www . java 2s . c o m*/ Option option = new Option(clo.name(), clo.description()); //Option option = new Option(clo.name(), clo.longName(), clo.argCount() > 0, clo.description()); if (StringUtils.isNotBlank(clo.longName())) { option.setLongOpt(clo.longName()); } //option.set` option.setArgs(clo.argCount()); option.setRequired(clo.required()); option.setOptionalArg(clo.optionalArg()); option.setValueSeparator(clo.valueSeparator()); return option; }
From source file:com.github.dakusui.symfonion.CLI.java
private Options buildOptions() { // create Options object Options options = new Options(); //////from w w w . ja v a 2 s . c om // Behavior options options.addOption("V", "version", false, "print the version information."); options.addOption("h", "help", false, "print the command line usage."); options.addOption("l", "list", false, "list the available midi devices."); options.addOption("p", "play", true, "play the specifiled file."); options.addOption("c", "compile", true, "compile the specified file to a standard midi file."); { Option option = OptionBuilder.create("r"); option.setLongOpt("route"); option.setValueSeparator('='); option.setArgs(2); option.setDescription("run a midi patch bay."); options.addOption(option); } //// // I/O options { Option option = OptionBuilder.create("O"); option.setValueSeparator('='); option.setArgs(2); option.setDescription("specify midi out port."); options.addOption(option); } { Option option = OptionBuilder.create("I"); option.setValueSeparator('='); option.setArgs(2); option.setDescription("specify midi in port."); options.addOption(option); } { Option option = OptionBuilder.create("o"); option.setArgs(1); option.setDescription("specify a file to which a compiled standard midi file is output."); options.addOption(option); } return options; }
From source file:edu.ksu.cis.indus.tools.slicer.SliceXMLizerCLI.java
/** * Parses the command line argument./* ww w . j a v a 2 s . co 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:it.jnrpe.plugins.factory.COption.java
Option toOption() { Option ret = new Option(m_sOption, m_sDescription); if (m_bArgsOptional != null) ret.setOptionalArg(m_bArgsOptional.booleanValue()); if (m_bHasArgs) { if (m_iArgsCount == null) ret.setArgs(Option.UNLIMITED_VALUES); }//w ww . j ava 2s . c o m ret.setRequired(m_bRequired); if (m_iArgsCount != null) ret.setArgs(m_iArgsCount.intValue()); if (m_sArgName != null) { if (m_iArgsCount == null) ret.setArgs(Option.UNLIMITED_VALUES); ret.setArgName(m_sArgName); } if (m_sLongOpt != null) ret.setLongOpt(m_sLongOpt); if (m_sValueSeparator != null && m_sValueSeparator.length() != 0) ret.setValueSeparator(m_sValueSeparator.charAt(0)); return ret; }
From source file:de.bmw.yamaica.common.console.CommandExecuter.java
private Option createOption(IConfigurationElement optionConfiguration) { String shortName = optionConfiguration.getAttribute(OPTION_SHORT_NAME_ATTRIBUTE_NAME); String longName = optionConfiguration.getAttribute(OPTION_LONG_NAME_ATTRIBUTE_NAME); String description = optionConfiguration.getAttribute(OPTION_DESCRIPTION_ATTRIBUTE_NAME); String required = optionConfiguration.getAttribute(OPTION_REQUIRED_ATTRIBUTE_NAME); String argCount = optionConfiguration.getAttribute(OPTION_ARG_COUNT_ATTRIBUTE_NAME); String argName = optionConfiguration.getAttribute(OPTION_ARG_NAME_ATTRIBUTE_NAME); String hasOptionalArg = optionConfiguration.getAttribute(OPTION_HAS_OPTIONAL_ARG_ATTRIBUTE_NAME); String valueSeparator = optionConfiguration.getAttribute(OPTION_VALUE_SEPARATOR_ATTRIBUTE_NAME); Option option = new Option(shortName, description); option.setRequired(Boolean.parseBoolean(required)); option.setArgs(Integer.parseInt(argCount)); option.setOptionalArg(Boolean.parseBoolean(hasOptionalArg)); if (null != longName) { option.setLongOpt(longName); }/*w ww.j a v a 2 s . co m*/ if (null != argName) { option.setArgName(argName); } if (null != valueSeparator) { option.setValueSeparator(valueSeparator.charAt(0)); } return option; }
From source file:com.trsst.Command.java
@SuppressWarnings("static-access") private void buildOptions(String[] argv, PrintStream out, InputStream in) { // NOTE: OptionsBuilder is NOT thread-safe // which was causing us random failures. Option o; portOptions = new Options(); o = new Option(null, "Specify port"); o.setRequired(false);/*from w ww. java 2 s . c om*/ o.setArgs(1); o.setLongOpt("port"); portOptions.addOption(o); o = new Option(null, "Expose client API"); o.setRequired(false); o.setArgs(0); o.setLongOpt("api"); portOptions.addOption(o); o = new Option(null, "Launch embedded GUI"); o.setRequired(false); o.setArgs(0); o.setLongOpt("gui"); portOptions.addOption(o); o = new Option(null, "Turn off SSL"); o.setRequired(false); o.setArgs(0); o.setLongOpt("clear"); portOptions.addOption(o); o = new Option(null, "Use TOR (experimental)"); o.setRequired(false); o.setArgs(0); o.setLongOpt("tor"); portOptions.addOption(o); pullOptions = new Options(); o = new Option("h", "Set host server for this operation"); o.setRequired(false); o.setArgs(1); o.setArgName("url"); o.setLongOpt("host"); pullOptions.addOption(o); o = new Option("d", "Decrypt entries as specified recipient id"); o.setRequired(false); o.setArgs(1); o.setArgName("id"); o.setLongOpt("decrypt"); pullOptions.addOption(o); postOptions = new Options(); o = new Option("a", "Attach the specified file, or - for std input"); o.setRequired(false); o.setOptionalArg(true); o.setArgName("file"); o.setLongOpt("attach"); postOptions.addOption(o); o = new Option("b", "Set base URL for this feed"); o.setRequired(false); o.setArgs(1); o.setArgName("url"); o.setLongOpt("base"); postOptions.addOption(o); o = new Option("p", "Specify passphrase on the command line"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("pass"); postOptions.addOption(o); o = new Option("s", "Specify status update on command line"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("status"); postOptions.addOption(o); o = new Option("u", "Attach the specified url to the new entry"); o.setRequired(false); o.setArgs(1); o.setArgName("url"); o.setLongOpt("url"); postOptions.addOption(o); o = new Option("v", "Specify an activitystreams verb for this entry"); o.setRequired(false); o.setArgs(1); o.setArgName("verb"); o.setLongOpt("verb"); postOptions.addOption(o); o = new Option("r", "Add a mention"); o.setRequired(false); o.setArgs(1); o.setArgName("id"); o.setLongOpt("mention"); postOptions.addOption(o); o = new Option("g", "Add a tag"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("tag"); postOptions.addOption(o); o = new Option("c", "Specify entry content on command line"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("content"); postOptions.addOption(o); o = new Option("t", "Set this feed's title"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("title"); postOptions.addOption(o); o = new Option(null, "Set this feed's subtitle"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("subtitle"); postOptions.addOption(o); o = new Option("n", "Set this feed's author name"); o.setRequired(false); o.setArgs(1); o.setArgName("text"); o.setLongOpt("name"); postOptions.addOption(o); o = new Option(null, "Set this feed's author uri"); o.setRequired(false); o.setArgs(1); o.setArgName("uri"); o.setLongOpt("uri"); postOptions.addOption(o); o = new Option("e", "Encrypt entry for specified public key"); o.setRequired(false); o.setArgs(1); o.setArgName("pubkey"); o.setLongOpt("encrypt"); postOptions.addOption(o); o = new Option("m", "Set this feed's author email"); o.setRequired(false); o.setArgs(1); o.setArgName("email"); o.setLongOpt("email"); postOptions.addOption(o); o = new Option("i", "Set as this feed's icon or specify url"); o.setRequired(false); o.setArgs(1); o.setArgName("url"); o.setLongOpt("icon"); postOptions.addOption(o); o = new Option("l", "Set as this feed's logo or specify url"); o.setRequired(false); o.setArgs(1); o.setArgName("url"); o.setLongOpt("logo"); postOptions.addOption(o); o = new Option(null, "Generate feed id with specified prefix"); o.setRequired(false); o.setArgs(1); o.setArgName("prefix"); o.setLongOpt("vanity"); postOptions.addOption(o); o = new Option(null, "Require SSL certs"); o.setRequired(false); o.setArgs(0); o.setLongOpt("strict"); postOptions.addOption(o); // merge options parameters mergedOptions = new Options(); for (Object obj : pullOptions.getOptions()) { mergedOptions.addOption((Option) obj); } for (Object obj : postOptions.getOptions()) { mergedOptions.addOption((Option) obj); } for (Object obj : portOptions.getOptions()) { mergedOptions.addOption((Option) obj); } helpOption = OptionBuilder.isRequired(false).withLongOpt("help").withDescription("Display these options") .create('?'); mergedOptions.addOption(helpOption); }
From source file:net.sourceforge.squirrel_sql.client.ApplicationArguments.java
private Option createAnOption(String[] argInfo) { Option opt = new Option(argInfo[0], argInfo[2]); if (!isStringEmpty(argInfo[1])) { opt.setLongOpt(argInfo[1]); }/* w w w.j a v a 2s . co m*/ return opt; }