List of usage examples for org.apache.commons.cli OptionBuilder withDescription
public static OptionBuilder withDescription(String newDescription)
From source file:org.magdaaproject.analysis.rhizome.RhizomeAnalysis.java
private static Options createOptions() { Options options = new Options(); // task type/*from ww w. ja v a2 s . c o m*/ OptionBuilder.withArgName("string"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("task to undertake"); OptionBuilder.isRequired(true); options.addOption(OptionBuilder.create("task")); // properties file path OptionBuilder.withArgName("path"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("path to the properties file"); OptionBuilder.isRequired(true); options.addOption(OptionBuilder.create("properties")); // table name OptionBuilder.withArgName("string"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("name of table to work with"); OptionBuilder.isRequired(true); options.addOption(OptionBuilder.create("table")); // path to input database OptionBuilder.withArgName("path"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("path to a single input rhizome database"); options.addOption(OptionBuilder.create("input")); // id of the tablet OptionBuilder.withArgName("string"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("id of the tablet"); options.addOption(OptionBuilder.create("tablet")); // parent directory of data to import OptionBuilder.withArgName("path"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("path to the parent directory of a dataset"); options.addOption(OptionBuilder.create("dataset")); // path to output file OptionBuilder.withArgName("path"); OptionBuilder.hasArg(true); OptionBuilder.withDescription("path to an output file"); options.addOption(OptionBuilder.create("output")); return options; }
From source file:org.midonet.midolman.tools.MmCtl.java
private static OptionGroup getOptionalOptionGroup() { OptionGroup optionalGroup = new OptionGroup(); OptionBuilder.hasArg();//from w w w.ja va 2 s . c o m OptionBuilder.withLongOpt("config"); OptionBuilder.withDescription("MM configuration file"); optionalGroup.addOption(OptionBuilder.create()); optionalGroup.setRequired(false); return optionalGroup; }
From source file:org.midonet.midolman.tools.MmCtl.java
private static OptionGroup getMutuallyExclusiveOptionGroup() { // The command line tool can only accept one of these options: OptionGroup mutuallyExclusiveOptions = new OptionGroup(); OptionBuilder.hasArgs(2);/*from w w w . ja v a 2s . c o m*/ OptionBuilder.isRequired(); OptionBuilder.withLongOpt("bind-port"); OptionBuilder.withDescription("Bind a port to an interface"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withLongOpt("unbind-port"); OptionBuilder.withDescription("Unbind a port from an interface"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt("list-hosts"); OptionBuilder.withDescription("List MidolMan agents in the system"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); // make sure that there is at least one. mutuallyExclusiveOptions.setRequired(true); return mutuallyExclusiveOptions; }
From source file:org.midonet.mmdpctl.Mmdpctl.java
public static void main(String... args) { Options options = new Options(); // The command line tool can only accept one of these options: OptionGroup mutuallyExclusiveOptions = new OptionGroup(); OptionBuilder.withDescription("List all the installed datapaths"); OptionBuilder.isRequired();// ww w. j ava2 s. c o m OptionBuilder.withLongOpt("list-dps"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); OptionBuilder.withDescription("Show all the information related to a given datapath."); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withLongOpt("show-dp"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); OptionBuilder.withDescription("Show all the flows installed for a given datapath."); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withLongOpt("dump-dp"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); OptionBuilder.withDescription("Add a new datapath."); OptionBuilder.hasArg(); OptionBuilder.withLongOpt("add-dp"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); OptionBuilder.withDescription("Delete a datapath."); OptionBuilder.hasArg(); OptionBuilder.withLongOpt("delete-dp"); mutuallyExclusiveOptions.addOption(OptionBuilder.create()); // make sure that there is at least one. mutuallyExclusiveOptions.setRequired(true); options.addOptionGroup(mutuallyExclusiveOptions); // add an optional timeout to the command. OptionBuilder.withDescription( "Specifies a timeout in seconds. " + "If the program is not able to get the results in less than " + "this amount of time it will stop and return with an error code"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt("timeout"); options.addOption(OptionBuilder.create()); CommandLineParser parser = new PosixParser(); try { CommandLine cl = parser.parse(options, args); Mmdpctl mmdpctl = new Mmdpctl(); // check if the user sets a (correct) timeout. if (cl.hasOption("timeout")) { String timeoutString = cl.getOptionValue("timeout"); Integer timeout = Integer.parseInt(timeoutString); if (timeout > 0) { log.info("Installing a timeout of {} seconds", timeout); mmdpctl.setTimeout(timeout); } else { System.out.println("The timeout needs to be a positive number, bigger than 0."); System.exit(1); } } if (cl.hasOption("list-dps")) { System.exit(mmdpctl.execute(new ListDatapathsCommand())); } else if (cl.hasOption("show-dp")) { System.exit(mmdpctl.execute(new GetDatapathCommand(cl.getOptionValue("show-dp")))); } else if (cl.hasOption("dump-dp")) { System.exit(mmdpctl.execute(new DumpDatapathCommand(cl.getOptionValue("dump-dp")))); } else if (cl.hasOption("add-dp")) { System.exit(mmdpctl.execute(new AddDatapathCommand(cl.getOptionValue("add-dp")))); } else if (cl.hasOption("delete-dp")) { System.exit(mmdpctl.execute(new DeleteDatapathCommand(cl.getOptionValue("delete-dp")))); } } catch (ParseException e) { showHelpAndExit(options, e.getMessage()); } System.exit(0); }
From source file:org.mitre.scap.xccdf.XCCDFInterpreter.java
/** * @param args the command line arguments *///www . ja v a 2s . c o m public static void main(String[] args) throws IOException, XmlException, URISyntaxException { XCCDFInterpreter.generateExecutionTimeStr(); BuildProperties buildProperties = BuildProperties.getInstance(); //System.out.println(); //System.out.println( buildProperties.getApplicationName()+" v"+ buildProperties.getApplicationVersion()+" build "+buildProperties.getApplicationBuild()); //System.out.println("--------------------"); //outputOsProperties(); //System.out.println("--------------------"); //System.out.println(); // Define the commandline options @SuppressWarnings("static-access") Option help = OptionBuilder.withDescription("display usage").withLongOpt("help").create('h'); @SuppressWarnings("static-access") Option workingDir = OptionBuilder.hasArg().withArgName("FILE").withDescription("use result directory FILE") .withLongOpt("result-dir").create('R'); @SuppressWarnings("static-access") Option xccdfResultFilename = OptionBuilder.hasArg().withArgName("FILENAME") .withDescription("use result filename FILENAME").withLongOpt("xccdf-result-filename").create("F"); @SuppressWarnings("static-access") Option nocpe = OptionBuilder.withDescription("do not process CPE references").withLongOpt("no-cpe") .create(); @SuppressWarnings("static-access") Option noresults = OptionBuilder.withDescription("do not display rule results").withLongOpt("no-results") .create(); @SuppressWarnings("static-access") Option nocheck = OptionBuilder.withDescription("do not process checks").withLongOpt("no-check").create(); @SuppressWarnings("static-access") Option profile = OptionBuilder.hasArg().withArgName("PROFILE").withDescription("use given profile id") .withLongOpt("profile-id").create('P'); @SuppressWarnings("static-access") Option ssValidation = OptionBuilder.hasArg().withArgName("SS-VALIDATION") .withDescription("use given validation id").withLongOpt("ssValidation-id").create("S"); @SuppressWarnings("static-access") Option cpeDictionary = OptionBuilder.hasArg().withArgName("FILE") .withDescription("use given CPE 2.0 Dictionary file").withLongOpt("cpe-dictionary").create('C'); @SuppressWarnings("static-access") Option cpeOVALDefinition = OptionBuilder.hasArg().withArgName("FILE") .withDescription("use given CPE OVAL definition file for CPE evaluation").withLongOpt("cpe-oval") .create('c'); @SuppressWarnings("static-access") Option verbose = OptionBuilder.withDescription("produce verbose output").create("v"); // Build the options list Options options = new Options(); options.addOption(help); options.addOption(workingDir); options.addOption(xccdfResultFilename); options.addOption(profile); options.addOption(ssValidation); options.addOption(nocpe); options.addOption(noresults); options.addOption(nocheck); options.addOption(cpeDictionary); options.addOption(cpeOVALDefinition); options.addOption(verbose); // create the parser CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String[] remainingArgs = line.getArgs(); if (line.hasOption("help") || remainingArgs.length != 1) { if (remainingArgs.length != 1) { System.err.print("Invalid arguments: "); for (String arg : remainingArgs) { System.err.print("'" + arg + "' "); } System.out.println(); } // automatically generate the help statement System.out.println(); showHelp(options); System.exit(0); } File xccdfFile = new File(remainingArgs[0]); if (!xccdfFile.exists()) { System.err.println( "!! the specified XCCDF file '" + xccdfFile.getAbsolutePath() + "' does not exist!"); System.exit(1); } XCCDFInterpreter interpreter = new XCCDFInterpreter(xccdfFile.getCanonicalFile()); //System.out.println("** validating XCCDF content"); if (!interpreter.validate()) { System.err.println("!! the XCCDF document is invalid. aborting."); System.exit(8); } if (line.hasOption(verbose.getOpt())) { verboseOutput = true; interpreter.setVerboseOutput(true); } if (line.hasOption(workingDir.getOpt())) { String lineOpt = line.getOptionValue(workingDir.getOpt()); String workingDirValue = (lineOpt == null) ? "" : lineOpt; File f = new File(workingDirValue); if (!f.exists()) { if (verboseOutput) System.out.println("** creating directory: " + f.getAbsolutePath()); if (!f.mkdirs()) { System.err.println("!! unable to create the result directory: " + f.getAbsolutePath()); System.exit(2); } } if (!f.isDirectory()) { System.err.println("!! the path specified for the result directory is not a directory: " + f.getAbsolutePath()); System.exit(3); } if (!f.canWrite()) { System.err.println("!! the path specified for the result directory is not writable: " + f.getAbsolutePath()); System.exit(4); } interpreter.setResultDirectory(f); } if (line.hasOption(xccdfResultFilename.getOpt())) { interpreter.setXccdfResultsFilename(line.getOptionValue(xccdfResultFilename.getOpt())); } if (line.hasOption(profile.getOpt())) { interpreter.setProfileId(line.getOptionValue(profile.getOpt())); } if (line.hasOption(ssValidation.getOpt())) { interpreter.setssValidationId(line.getOptionValue(ssValidation.getOpt())); } if (line.hasOption(nocpe.getLongOpt())) { interpreter.setProcessCPE(false); } if (line.hasOption(noresults.getLongOpt())) { interpreter.setDisplayResults(false); } if (line.hasOption(nocheck.getLongOpt())) { interpreter.setProcessChecks(false); } if (interpreter.processCPE == true) { if (line.hasOption(cpeDictionary.getOpt())) { String lineOpt = line.getOptionValue(cpeDictionary.getOpt()); String cpeDict = (lineOpt == null) ? "" : lineOpt; File f = new File(cpeDict); if (!f.exists()) { System.err.println("The CPE dictionary file does not exist: " + f.getAbsolutePath()); System.exit(5); } if (!f.isFile()) { System.err.println("The path specified for the CPE dictionary file is not a file: " + f.getAbsolutePath()); System.exit(6); } if (!f.canRead()) { System.err.println("The path specified for the CPE dictionary file is not readable: " + f.getAbsolutePath()); System.exit(7); } interpreter.setCPEDictionaryFile(f); } if (line.hasOption(cpeOVALDefinition.getOpt())) { String lineOpt = line.getOptionValue(cpeOVALDefinition.getOpt()); String cpeOVAL = (lineOpt == null) ? "" : lineOpt; File f = new File(cpeOVAL); if (!f.exists()) { System.err.println( "!! the CPE OVAL inventory definition file does not exist: " + f.getAbsolutePath()); System.exit(5); } if (!f.isFile()) { System.err.println( "!! the path specified for the CPE OVAL inventory definition file is not a file: " + f.getAbsolutePath()); System.exit(6); } if (!f.canRead()) { System.err.println( "!! the path specified for the CPE OVAL inventory definition file is not readable: " + f.getAbsolutePath()); System.exit(7); } interpreter.setCPEOVALDefinitionFile(f); } } // END IF processCPE interpreter.process(); } catch (ParseException ex) { System.err.println("!! parsing failed : " + ex.getMessage()); System.out.println(); showHelp(options); } catch (ProfileNotFoundException ex) { if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } catch (CircularReferenceException ex) { System.err.println("!! checklist processing failed : " + ex.getMessage()); if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } catch (ExtensionScopeException ex) { if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } catch (ItemNotFoundException ex) { if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } catch (PropertyNotFoundException ex) { if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } catch (CPEEvaluationException ex) { if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } catch (Exception ex) { if (verboseOutput == true) ex.printStackTrace(); else System.err.println("!! checklist processing failed : " + ex.getMessage()); } }
From source file:org.movsim.input.MovsimCommandLine.java
private void createOptions() { options = new Options(); options.addOption("h", "help", false, "prints this message"); options.addOption("v", "validate", false, "parses xml input file for validation (without simulation)"); options.addOption("w", "write_xsd", false, "writes xsd file to output (for convenience/lookup schema definitions)"); options.addOption("l", "log", false, "writes the file \"log4j.properties\" to file to adjust the logging properties on an individual level"); options.addOption("d", "write_dot", false, "writes a 'dot' network file for further analysis of the xodr"); options.addOption("s", "simulation scanning mode", false, "invokes the simulator repeatedly in a loop (needs to be programmed by user)"); OptionBuilder.withArgName("file"); OptionBuilder.hasArg();/* ww w . j a v a2s.c o m*/ ProjectMetaData.getInstance(); OptionBuilder.withDescription("movsim main configuration file (ending \"" + ProjectMetaData.getMovsimConfigFileEnding() + "\" will be added automatically if not provided."); final Option xmlSimFile = OptionBuilder.create("f"); options.addOption(xmlSimFile); OptionBuilder.withArgName("directory"); OptionBuilder.hasArg(); OptionBuilder.withDescription("argument is the output path relative to calling directory"); final Option outputPathOption = OptionBuilder.create("o"); options.addOption(outputPathOption); }
From source file:org.neovera.jdiablo.internal.OptionAnnotatedProperty.java
@SuppressWarnings("static-access") public org.apache.commons.cli.Option getCliOption() { if (_cliOption != null) { return _cliOption; } else {/*w w w .j ava2 s.com*/ Option option = getOption(); OptionBuilder builder = OptionBuilder.withDescription(option.description()); if (StringUtils.isNotBlank(option.argName())) { builder = builder.withArgName(option.argName()); } if (option.args() != 0) { builder = builder.hasArgs(option.args()); } if (option.hasArgs()) { builder = builder.hasArgs(); } if (StringUtils.isNotBlank(option.longOption())) { builder = builder.withLongOpt(option.longOption()); } if (option.optionalArgs() != 0) { builder = builder.hasOptionalArgs(option.optionalArgs()); } if (option.required() && !getOptionProperty().isOptionNotRequiredOverride()) { builder = builder.isRequired(); } if (option.valueSeparator() != ' ') { builder = builder.withValueSeparator(option.valueSeparator()); } setCliOption(builder.create(option.shortOption())); return getCliOption(); } }
From source file:org.nuunframework.cli.NuunCliPlugin.java
private Option createOptionFromField(Field field) { Option option = null;/*from ww w. j a v a2 s. c o m*/ // Cli Option Builder is completly static :-/ // so we synchronized it ... synchronized (OptionBuilder.class) { // reset the builder creating a dummy option OptionBuilder.withLongOpt("dummy"); OptionBuilder.create(); // NuunOption nuunOption = field.getAnnotation(NuunOption.class); if (nuunOption == null) { for (Annotation anno : field.getAnnotations()) { if (AssertUtils.hasAnnotationDeep(anno.annotationType(), NuunOption.class)) { nuunOption = AssertUtils.annotationProxyOf(NuunOption.class, anno); break; } } } // longopt if (!Strings.isNullOrEmpty(nuunOption.longOpt())) { OptionBuilder.withLongOpt(nuunOption.longOpt()); } // description if (!Strings.isNullOrEmpty(nuunOption.description())) { OptionBuilder.withDescription(nuunOption.description()); } // required OptionBuilder.isRequired((nuunOption.required())); // arg OptionBuilder.hasArg((nuunOption.arg())); // args if (nuunOption.args()) { if (nuunOption.numArgs() > 0) { OptionBuilder.hasArgs(nuunOption.numArgs()); } else { OptionBuilder.hasArgs(); } } // is optional if (nuunOption.optionalArg()) { OptionBuilder.hasOptionalArg(); } // nuun OptionBuilder.withValueSeparator(nuunOption.valueSeparator()); // opt if (!Strings.isNullOrEmpty(nuunOption.opt())) { option = OptionBuilder.create(nuunOption.opt()); } else { option = OptionBuilder.create(); } } return option; }
From source file:org.nuxeo.launcher.NuxeoLauncher.java
/** * @since 5.6//from w w w.j a v a 2s . c o m */ protected static void initParserOptions() { if (launcherOptions == null) { launcherOptions = new Options(); // help option OptionBuilder.withLongOpt(OPTION_HELP); OptionBuilder.withDescription(OPTION_HELP_DESC); launcherOptions.addOption(OptionBuilder.create("h")); // Quiet option OptionBuilder.withLongOpt(OPTION_QUIET); OptionBuilder.withDescription(OPTION_QUIET_DESC); launcherOptions.addOption(OptionBuilder.create("q")); // Debug option OptionBuilder.withLongOpt(OPTION_DEBUG); OptionBuilder.withDescription(OPTION_DEBUG_DESC); launcherOptions.addOption(OptionBuilder.create("d")); // Debug category option OptionBuilder.withDescription(OPTION_DEBUG_CATEGORY_DESC); OptionBuilder.hasArg(); launcherOptions.addOption(OptionBuilder.create(OPTION_DEBUG_CATEGORY)); OptionGroup outputOptions = new OptionGroup(); // Hide deprecation warnings option OptionBuilder.withLongOpt(OPTION_HIDE_DEPRECATION); OptionBuilder.withDescription(OPTION_HIDE_DEPRECATION_DESC); outputOptions.addOption(OptionBuilder.create()); // XML option OptionBuilder.withLongOpt(OPTION_XML); OptionBuilder.withDescription(OPTION_XML_DESC); outputOptions.addOption(OptionBuilder.create()); // JSON option OptionBuilder.withLongOpt(OPTION_JSON); OptionBuilder.withDescription(OPTION_JSON_DESC); outputOptions.addOption(OptionBuilder.create()); launcherOptions.addOptionGroup(outputOptions); // GUI option OptionBuilder.withLongOpt(OPTION_GUI); OptionBuilder.hasArg(); OptionBuilder.withArgName("true|false"); OptionBuilder.withDescription(OPTION_GUI_DESC); launcherOptions.addOption(OptionBuilder.create()); // Package management option OptionBuilder.withLongOpt(OPTION_NODEPS); OptionBuilder.withDescription(OPTION_NODEPS_DESC); launcherOptions.addOption(OptionBuilder.create()); // Relax on target platform option OptionBuilder.withLongOpt(OPTION_RELAX); OptionBuilder.hasArg(); OptionBuilder.withArgName("true|false|ask"); OptionBuilder.withDescription(OPTION_RELAX_DESC); launcherOptions.addOption(OptionBuilder.create()); // Accept option OptionBuilder.withLongOpt(OPTION_ACCEPT); OptionBuilder.hasArg(); OptionBuilder.withArgName("true|false|ask"); OptionBuilder.withDescription(OPTION_ACCEPT_DESC); launcherOptions.addOption(OptionBuilder.create()); } }
From source file:org.obiba.bitwise.client.OpenCommand.java
public Option getOption() { return OptionBuilder.withDescription("change the current active store").withLongOpt("open").hasArg() .withArgName("storeName").create('o'); }