List of usage examples for org.apache.commons.cli OptionBuilder withDescription
public static OptionBuilder withDescription(String newDescription)
From source file:com.comcast.oscar.cli.commands.MergeBulk.java
/** * Set option parameters for command Maximum CPE * @return Option/*ww w . ja v a 2 s.com*/ */ public static final Option OptionParameters() { OptionBuilder.withArgName("input dirs> <o=<output dir>> <e=<extension>> <b{inary}/t{ext}"); OptionBuilder.hasArgs(); OptionBuilder.hasOptionalArgs(); OptionBuilder.withValueSeparator(' '); OptionBuilder.withLongOpt("mergebulkbuild"); OptionBuilder.withDescription("Merge multiple text files from directories into one binary. " + "EX: -mbb inputDirectoryModel inputDirectoryTier inputDirectoryCPE o=outputDirectory e=bin text. " + "Output directory, extension and b{inary}/t{ext} are optional."); return OptionBuilder.create("mbb"); }
From source file:com.delcyon.capo.Configuration.java
@SuppressWarnings({ "unchecked", "static-access" }) public Configuration(String... programArgs) throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = documentBuilderFactory.newDocumentBuilder(); options = new Options(); // the enum this is a little complicated, but it gives us a nice // centralized place to put all of the system parameters // and lets us iterate of the list of options and preferences PREFERENCE[] preferences = PREFERENCE.values(); for (PREFERENCE preference : preferences) { // not the most elegant, but there is no default constructor, but // the has arguments value is always there OptionBuilder optionBuilder = OptionBuilder.hasArg(preference.hasArgument); if (preference.hasArgument == true) { String[] argNames = preference.arguments; for (String argName : argNames) { optionBuilder = optionBuilder.withArgName(argName); }/* ww w . j ava 2s. c o m*/ } optionBuilder = optionBuilder.withDescription(preference.getDescription()); optionBuilder = optionBuilder.withLongOpt(preference.getLongOption()); options.addOption(optionBuilder.create(preference.getOption())); preferenceHashMap.put(preference.toString(), preference); } //add dynamic options Set<String> preferenceProvidersSet = CapoApplication.getAnnotationMap() .get(PreferenceProvider.class.getCanonicalName()); if (preferenceProvidersSet != null) { for (String className : preferenceProvidersSet) { Class preferenceClass = Class.forName(className).getAnnotation(PreferenceProvider.class) .preferences(); if (preferenceClass.isEnum()) { Object[] enumObjects = preferenceClass.getEnumConstants(); for (Object enumObject : enumObjects) { Preference preference = (Preference) enumObject; //filter out any preferences that don't belong on this server or client. if (preference.getLocation() != Location.BOTH) { if (CapoApplication.isServer() == true && preference.getLocation() == Location.CLIENT) { continue; } else if (CapoApplication.isServer() == false && preference.getLocation() == Location.SERVER) { continue; } } preferenceHashMap.put(preference.toString(), preference); boolean hasArgument = false; if (preference.getArguments() == null || preference.getArguments().length == 0) { hasArgument = false; } else { hasArgument = true; } OptionBuilder optionBuilder = OptionBuilder.hasArg(hasArgument); if (hasArgument == true) { String[] argNames = preference.getArguments(); for (String argName : argNames) { optionBuilder = optionBuilder.withArgName(argName); } } optionBuilder = optionBuilder.withDescription(preference.getDescription()); optionBuilder = optionBuilder.withLongOpt(preference.getLongOption()); options.addOption(optionBuilder.create(preference.getOption())); } } } } // create parser CommandLineParser commandLineParser = new GnuParser(); this.commandLine = commandLineParser.parse(options, programArgs); Preferences systemPreferences = Preferences .systemNodeForPackage(CapoApplication.getApplication().getClass()); String capoDirString = null; while (true) { capoDirString = systemPreferences.get(PREFERENCE.CAPO_DIR.longOption, null); if (capoDirString == null) { systemPreferences.put(PREFERENCE.CAPO_DIR.longOption, PREFERENCE.CAPO_DIR.defaultValue); capoDirString = PREFERENCE.CAPO_DIR.defaultValue; try { systemPreferences.sync(); } catch (BackingStoreException e) { //e.printStackTrace(); if (systemPreferences.isUserNode() == false) { System.err.println("Problem with System preferences, trying user's"); systemPreferences = Preferences .userNodeForPackage(CapoApplication.getApplication().getClass()); continue; } else //just bail out { throw e; } } } break; } disableAutoSync = hasOption(PREFERENCE.DISABLE_CONFIG_AUTOSYNC); File capoDirFile = new File(capoDirString); if (capoDirFile.exists() == false) { if (disableAutoSync == false) { capoDirFile.mkdirs(); } } File configDir = new File(capoDirFile, PREFERENCE.CONFIG_DIR.defaultValue); if (configDir.exists() == false) { if (disableAutoSync == false) { configDir.mkdirs(); } } if (disableAutoSync == false) { capoConfigFile = new File(configDir, CONFIG_FILENAME); if (capoConfigFile.exists() == false) { Document configDocument = CapoApplication.getDefaultDocument("config.xml"); FileOutputStream configFileOutputStream = new FileOutputStream(capoConfigFile); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(configDocument), new StreamResult(configFileOutputStream)); configFileOutputStream.close(); } configDocument = documentBuilder.parse(capoConfigFile); } else //going memory only, because of disabled auto sync { configDocument = CapoApplication.getDefaultDocument("config.xml"); } if (configDocument instanceof CDocument) { ((CDocument) configDocument).setSilenceEvents(true); } loadPreferences(); preferenceValueHashMap.put(PREFERENCE.CAPO_DIR.longOption, capoDirString); //print out preferences //this also has the effect of persisting all of the default values if a values doesn't already exist for (PREFERENCE preference : preferences) { if (getValue(preference) != null) { CapoApplication.logger.log(Level.CONFIG, preference.longOption + "='" + getValue(preference) + "'"); } } CapoApplication.logger.setLevel(Level.parse(getValue(PREFERENCE.LOGGING_LEVEL))); }
From source file:com.comcast.oscar.cli.commands.HexDisplay.java
/** * Set option parameters for command Hexidecimal display * @return Option/* ww w . j a v a 2 s. c om*/ */ public static final Option OptionParameters() { OptionBuilder.withArgName("t{oplevel}"); OptionBuilder.hasArgs(1); OptionBuilder.hasOptionalArgs(); OptionBuilder.withValueSeparator(' '); OptionBuilder.withLongOpt("hex"); OptionBuilder.withDescription( "Display the hex of the input file. Option t creates a newline at the start of every top level TLV (binary files only)."); return OptionBuilder.create("x"); }
From source file:de.weltraumschaf.groundzero.opt.commons.OptionsConfiguration.java
/** * Initializes {@link #options} with all information the options parser needs. *///www .j av a 2 s . c om public OptionsConfiguration() { super(); // w/ argument OptionBuilder.withDescription(OptionDescriptor.PATH_PREFIX.getDescription()); OptionBuilder.withArgName("PATH"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt(OptionDescriptor.PATH_PREFIX.getLongOption()); options.addOption(OptionBuilder.create(OptionDescriptor.PATH_PREFIX.getShortOption())); OptionBuilder.withDescription(OptionDescriptor.INPUT_ENCODING.getDescription()); OptionBuilder.withArgName("ENCODING"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt(OptionDescriptor.INPUT_ENCODING.getLongOption()); options.addOption(OptionBuilder.create(OptionDescriptor.INPUT_ENCODING.getShortOption())); OptionBuilder.withDescription(OptionDescriptor.OUTPUT_ENCODING.getDescription()); OptionBuilder.withArgName("ENCODING"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt(OptionDescriptor.OUTPUT_ENCODING.getLongOption()); options.addOption(OptionBuilder.create(OptionDescriptor.OUTPUT_ENCODING.getShortOption())); // w/o argument options.addOption(OptionDescriptor.DEBUG.getShortOption(), OptionDescriptor.DEBUG.getLongOption(), false, OptionDescriptor.DEBUG.getDescription()); options.addOption(OptionDescriptor.HELP.getShortOption(), OptionDescriptor.HELP.getLongOption(), false, OptionDescriptor.HELP.getDescription()); options.addOption(OptionDescriptor.VERSION.getShortOption(), OptionDescriptor.VERSION.getLongOption(), false, OptionDescriptor.VERSION.getDescription()); }
From source file:com.vectorization.client.Application.java
private static Options createOptions() { Options options = new Options(); options.addOption("D", "database", true, "Database to use."); options.addOption("h", "host", true, "Connect to host."); OptionBuilder.withLongOpt("help"); OptionBuilder.withDescription("Print this message"); Option help = OptionBuilder.create(); options.addOption(help);/*from w w w . j ava 2s .c o m*/ Option passwordOption = new Option("p", "password", true, "Password to use when connecting " + "to server. If password is not " + "given it's asked from the tty."); passwordOption.setOptionalArg(true); options.addOption(passwordOption); options.addOption("P", "port", true, "Port number to use for connection"); options.addOption("u", "user", true, "User for login if not current user."); options.addOption("V", "version", false, "Output version information and exit."); return options; }
From source file:it.crs4.seal.tsv_sort.TsvSortOptionParser.java
@SuppressWarnings("static") // for OptionBuilder public TsvSortOptionParser() { super(ConfigSection, "seal tsvsort"); // define custom options keyOption = OptionBuilder .withDescription(//w w w . ja v a 2 s . c o m "sort key list. Comma-separated numbers, ranges specified with '-' [default: whole line]") .hasArg().withArgName("index[-last_index]").withLongOpt("key").create("k"); options.addOption(keyOption); delimiterOption = OptionBuilder.withDescription("character string that delimits fields [default: <TAB>]") .hasArg().withArgName("DELIM").withLongOpt("field-separator").create("t"); options.addOption(delimiterOption); this.setMinReduceTasks(1); }
From source file:it.crs4.seal.read_sort.ReadSortOptionParser.java
@SuppressWarnings("static") // for OptionBuilder public ReadSortOptionParser() { super(ConfigSection, "seal read_sort"); // define the custom options ann = OptionBuilder .withDescription("annotation file (.ann) of the BWA reference used to create the SAM data").hasArg() .withArgName("ref.ann").withLongOpt("annotations").create("ann"); options.addOption(ann);//www. j a v a 2 s . co m distReference = OptionBuilder .withDescription( "BWA reference on HDFS used to create the SAM data, to be distributed by DistributedCache") .hasArg().withArgName("archive").withLongOpt("distributed-reference").create("distref"); options.addOption(distReference); this.setMinReduceTasks(1); }
From source file:com.rockagen.commons.util.CLITest.java
@Test @Ignore//from www .j a v a 2s.com public void testCLI() { // create the Options Options options = new Options(); options.addOption("h", "help", false, "print help for the command."); options.addOption("v", "verbose", false, "verbose"); OptionBuilder.withArgName("property=value"); OptionBuilder.hasArgs(2); OptionBuilder.withLongOpt("desc"); OptionBuilder.withValueSeparator(); OptionBuilder.withDescription("use value for given property"); options.addOption(OptionBuilder.create("D")); OptionBuilder.withArgName("file1,file2..."); OptionBuilder.hasArgs(); OptionBuilder.withLongOpt("input"); OptionBuilder.withValueSeparator(' '); OptionBuilder.withDescription("file name"); options.addOption(OptionBuilder.create("i")); String formatstr = "CLITest [-h/--help][-v/--verbose].."; try { String[] args = { "CLITest", "--help", "-v", "-s", "--desc", "name=value", "--input", "file1", "file2", "file3" }; // parse the command line arguments CommandLine line = CmdUtil.parse(options, args); if (line.hasOption("h")) { CmdUtil.printHelp(formatstr, "weclome usa", options, "If you hava some quesion,please mail to agen@rockagen.com"); } if (line.hasOption("v")) { System.out.println("VERSION 0.0.1"); } if (line.hasOption("D")) { System.out.println("hey,guys,you input " + ArrayUtil.toString(line.getOptionValues("D"))); } if (line.hasOption("i")) { System.out.println("hey,guys,you input " + ArrayUtil.toString(line.getOptionValues("i"))); } else { CmdUtil.printHelp(formatstr, options); } } catch (ParseException exp) { CmdUtil.printHelp(formatstr, options); System.err.println(); System.err.println(exp.getMessage()); } }
From source file:it.crs4.seal.recab.RecabTableOptionParser.java
@SuppressWarnings("static") // for OptionBuilder public RecabTableOptionParser() { super(ConfigSection, "seal recab_table"); // define the options vcfFileOpt = OptionBuilder.withDescription("VCF file with known variation sites").hasArg() .withArgName("FILE").withLongOpt("vcf-file").create("vcf"); options.addOption(vcfFileOpt);/*from w w w . ja v a 2 s . c om*/ rodFileOpt = OptionBuilder.withDescription("ROD file with known variation sites").hasArg() .withArgName("FILE").withLongOpt("rod-file").create("rod"); options.addOption(rodFileOpt); this.setMinReduceTasks(1); this.setAcceptedInputFormats(new String[] { "bam", "sam" }); conf = null; }
From source file:com.vectorization.server.master.Application.java
private static Options createOptions() { Options options = new Options(); OptionBuilder.withLongOpt("help"); OptionBuilder.withDescription("Print this message"); Option help = OptionBuilder.create(); options.addOption(help);/*from ww w. j av a2 s .c o m*/ options.addOption("P", "port", true, "Port number to use for connection"); options.addOption("V", "version", false, "Output version information and exit."); return options; }