List of usage examples for org.apache.commons.cli OptionGroup addOption
public OptionGroup addOption(Option option)
Option
to this group. From source file:org.jini.commands.utils.DateCalc.java
/** * In this method all the specific Command Line options are defined. * *///from w w w . j ava 2s. co m @Override @SuppressWarnings("static-access") public void setJCLIOptions() { Option Help = new Option("h", "help", false, "Show Help."); this.jcOptions.addOption(Help); OptionGroup jcGroup = new OptionGroup(); Option diff = new Option("diff", "difference", false, "Calculate Difference between dates."); diff.setArgs(2); jcGroup.addOption(diff); Option addDays = new Option("a", "add", false, "Add days to date."); addDays.setArgs(2); jcGroup.addOption(addDays); this.jcOptions.addOptionGroup(jcGroup); }
From source file:org.jini.commands.utils.TextConvert.java
/** * In this method all the specific Command Line options are defined. * *//*from w w w . j a va 2 s.c om*/ @Override @SuppressWarnings("static-access") public void setJCLIOptions() { Option Help = new Option("h", "help", false, "Show Help."); this.jcOptions.addOption(Help); this.jcOptions.addOption(OptionBuilder.withLongOpt("file").withDescription("File to Convert") .isRequired(false).hasArg().create("f")); //this.jcOptions.addOption(OptionBuilder.withLongOpt("outputfile").withDescription("Output File").isRequired(false).hasArg().create("of")); OptionGroup jcGroup = new OptionGroup(); jcGroup.addOption( OptionBuilder.withLongOpt("texttobinary").withDescription("Convert text to Binary").create("ttb")); jcGroup.addOption( OptionBuilder.withLongOpt("binarytotext").withDescription("Convert binary to text").create("btt")); this.jcOptions.addOptionGroup(jcGroup); }
From source file:org.jini.commands.utils.TimeInZone.java
/** * In this method all the specific Command Line options are defined. * *//*from w ww .ja va 2s . c o m*/ @Override @SuppressWarnings("static-access") public void setJCLIOptions() { Option Help = new Option("h", "help", false, "Show Help."); this.jcOptions.addOption(Help); this.jcOptions.addOption(OptionBuilder.withLongOpt("search").withDescription("Search for a TimeZone") .isRequired(false).hasArg().create("s")); OptionGroup jcGroup = new OptionGroup(); jcGroup.addOption(OptionBuilder.withLongOpt("zone").withDescription("Zone Name").hasArg(true) .isRequired(false).create("z")); jcGroup.addOption(OptionBuilder.withLongOpt("list").withDescription("List").hasArg(false).isRequired(false) .create("l")); this.jcOptions.addOptionGroup(jcGroup); }
From source file:org.krysalis.barcode4j.cli.Main.java
private Options getOptions() { if (options == null) { this.options = new Options(); Option opt;//w ww. j av a 2 s . co m this.options.addOption( OptionBuilder.withLongOpt("verbose").withDescription("enable debug output").create('v')); //Group: file/stdout this.options.addOption(OptionBuilder.withLongOpt("output").withArgName("file").hasArg() .withDescription("the output filename").create('o')); //Group: config file/barcode type OptionGroup group = new OptionGroup(); group.setRequired(true); group.addOption(OptionBuilder.withArgName("file").withLongOpt("config").hasArg() .withDescription("the config file").create('c')); group.addOption(OptionBuilder.withArgName("name").withLongOpt("symbol").hasArg().withDescription( "the barcode symbology to select " + "(default settings, use -c if you want to customize)") .create('s')); this.options.addOptionGroup(group); //Output format type this.options.addOption(OptionBuilder.withArgName("format").withLongOpt("format").hasArg() .withDescription("the output format: MIME type or file " + "extension\n" + "Default: " + MimeTypes.MIME_SVG + " (SVG)") .create('f')); //Bitmap-specific options this.options.addOption(OptionBuilder.withArgName("integer").withLongOpt("dpi").hasArg() .withDescription("(for bitmaps) the image resolution in dpi\n" + "Default: 300").create('d')); this.options.addOption(OptionBuilder.withLongOpt("bw") .withDescription( "(for bitmaps) create monochrome (1-bit) " + "image instead of grayscale (8-bit)") .create()); } return this.options; }
From source file:org.linqs.psl.cli.Launcher.java
private static Options setupOptions() { Options options = new Options(); OptionGroup mainCommand = new OptionGroup(); mainCommand.addOption(Option.builder(OPERATION_INFER).longOpt(OPERATION_INFER_LONG) .desc("Run MAP inference." + " You can optionally supply a fully qualified name for an inference application" + " (defaults to " + DEFAULT_IA + ").") .hasArg().argName("inferenceMethod").optionalArg(true).build()); mainCommand.addOption(Option.builder(OPERATION_LEARN).longOpt(OPERATION_LEARN_LONG) .desc("Run weight learning." + " You can optionally supply a fully qualified name for a weight learner" + " (defaults to " + DEFAULT_WLA + ").") .hasArg().argName("learner").optionalArg(true).build()); // Make sure that help and version are in the main group so a successful run can use them. mainCommand.addOption(Option.builder(OPTION_HELP).longOpt(OPTION_HELP_LONG) .desc("Print this help message and exit").build()); mainCommand.addOption(Option.builder(OPTION_VERSION).longOpt(OPTION_VERSION_LONG) .desc("Print the PSL version and exit").build()); mainCommand.setRequired(true);// w w w . j av a2s . c om options.addOptionGroup(mainCommand); options.addOption(Option.builder(OPTION_DATA).longOpt(OPTION_DATA_LONG).desc("Path to PSL data file") .hasArg().argName("path").build()); options.addOption(Option.builder().longOpt(OPTION_DB_H2_PATH) .desc("Path for H2 database file (defaults to 'cli_<user name>@<host name>' ('" + DEFAULT_H2_DB_PATH + "'))." + " Not compatible with the '--" + OPTION_DB_POSTGRESQL_NAME + "' option.") .hasArg().argName("path").build()); options.addOption(Option.builder().longOpt(OPTION_DB_POSTGRESQL_NAME) .desc("Name for the PostgreSQL database to use (defaults to " + DEFAULT_POSTGRES_DB_NAME + ")." + " Not compatible with the '--" + OPTION_DB_H2_PATH + "' option." + " Currently only local databases without credentials are supported.") .hasArg().argName("name").optionalArg(true).build()); options.addOption(Option.builder(OPTION_EVAL).longOpt(OPTION_EVAL_LONG) .desc("Run the named evaluator (" + Evaluator.class.getName() + ") on any open predicate with a 'truth' partition.") .hasArg().argName("evaluator").build()); options.addOption(Option.builder(OPTION_INT_IDS).longOpt(OPTION_INT_IDS_LONG) .desc("Use integer identifiers (UniqueIntID) instead of string identifiers (UniqueStringID).") .build()); options.addOption(Option.builder(OPTION_LOG4J).longOpt(OPTION_LOG4J_LONG) .desc("Optional log4j properties file path").hasArg().argName("path").build()); options.addOption(Option.builder(OPTION_MODEL).longOpt(OPTION_MODEL_LONG).desc("Path to PSL model file") .hasArg().argName("path").build()); options.addOption(Option.builder(OPTION_OUTPUT_DIR).longOpt(OPTION_OUTPUT_DIR_LONG) .desc("Optional path for writing results to filesystem (default is STDOUT)").hasArg() .argName("path").build()); options.addOption(Option.builder(OPTION_PROPERTIES_FILE).longOpt(OPTION_PROPERTIES_FILE_LONG) .desc("Optional PSL properties file path").hasArg().argName("path").build()); options.addOption(Option.builder(OPTION_PROPERTIES).argName("name=value") .desc("Directly specify PSL properties (overrides options set via --" + OPTION_PROPERTIES_FILE_LONG + ")." + " See https://github.com/linqs/psl/wiki/Configuration-Options for a list of available options." + " Log4j properties (properties starting with 'log4j') will be passed to the logger." + " 'log4j.threshold=DEBUG', for example, will be passed to log4j and set the global logging threshold.") .hasArg().numberOfArgs(2).valueSeparator('=').build()); return options; }
From source file:org.marketcetera.ors.security.ORSAdminCLI.java
/** * Returns the options accepted by the CLI. * * @return the options accepted by the CLI *///from w w w . j a v a2 s .c o m private static Options options() { Options opts = new Options(); opts.addOption(OptionBuilder.hasArg().withArgName(CLI_ARG_LOGIN_VALUE.getText()) .withDescription(CLI_PARM_USER.getText()).isRequired(true).create(OPT_CURRENT_USER)); opts.addOption(OptionBuilder.hasArg().withArgName(CLI_ARG_LOGIN_PASSWORD_VALUE.getText()) .withDescription(CLI_PARM_PASSWORD.getText()).isRequired(false).create(OPT_CURRENT_PASSWORD)); OptionGroup commands = new OptionGroup(); commands.setRequired(true); commands.addOption(OptionBuilder.withLongOpt(CMD_LIST_USERS).withDescription(CLI_CMD_LIST_USERS.getText()) .isRequired().create()); commands.addOption(OptionBuilder.withLongOpt(CMD_ADD_USER).withDescription(CLI_CMD_ADD_USER.getText()) .isRequired().create()); commands.addOption(OptionBuilder.withLongOpt(CMD_DELETE_USER).withDescription(CLI_CMD_DELETE_USER.getText()) .isRequired().create()); commands.addOption(OptionBuilder.withLongOpt(CMD_RESTORE_USER) .withDescription(CLI_CMD_RESTORE_USER.getText()).isRequired().create()); commands.addOption(OptionBuilder.withLongOpt(CMD_CHANGE_PASS) .withDescription(CLI_CMD_CHANGE_PASSWORD.getText()).isRequired().create()); commands.addOption(OptionBuilder.withLongOpt(CMD_CHANGE_SUPERUSER) .withDescription(CLI_CMD_CHANGE_SUPERUSER.getText()).isRequired().create()); opts.addOptionGroup(commands); //Add optional arguments opts.addOption(OptionBuilder.withLongOpt("username"). //$NON-NLS-1$ hasArg().withArgName(CLI_ARG_USER_NAME_VALUE.getText()).withDescription(CLI_PARM_OP_USER.getText()) .isRequired(false).create(OPT_OPERATED_USER)); opts.addOption(OptionBuilder.withLongOpt("password"). //$NON-NLS-1$ hasArg().withArgName(CLI_ARG_USER_PASSWORD_VALUE.getText()) .withDescription(CLI_PARM_OP_PASSWORD.getText()).isRequired(false).create(OPT_OPERATED_PASSWORD)); opts.addOption(OptionBuilder.withLongOpt("superuser"). //$NON-NLS-1$ hasArg().withArgName(CLI_ARG_USER_SUPERUSER_VALUE.getText()) .withDescription(CLI_PARM_OP_SUPERUSER.getText()).isRequired(false).create(OPT_OPERATED_SUPERUSER)); opts.addOption(OptionBuilder.withLongOpt("active"). //$NON-NLS-1$ hasArg().withArgName(CLI_ARG_USER_ACTIVE_VALUE.getText()) .withDescription(CLI_PARM_OP_ACTIVE.getText()).isRequired(false).create(OPT_OPERATED_ACTIVE)); return opts; }
From source file:org.midonet.midolman.tools.MmCtl.java
private static OptionGroup getOptionalOptionGroup() { OptionGroup optionalGroup = new OptionGroup(); OptionBuilder.hasArg();//from w w w . j a v a 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. j a v a 2s.co 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();/*from w ww.j av a2 s .c om*/ 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.mrgeo.cmd.ingest.IngestImage.java
public static Options createOptions() { Options result = MrGeo.createOptions(); Option output = new Option("o", "output", true, "MrsPyramid image name"); output.setRequired(true);/*w w w . j a v a 2s . c o m*/ result.addOption(output); Option cat = new Option("c", "categorical", false, "Input [pixels] are categorical values"); cat.setRequired(false); result.addOption(cat); Option pyramid = new Option("sp", "skippyramid", false, "Skip building pyramids"); pyramid.setRequired(false); result.addOption(pyramid); Option recurse = new Option("nr", "norecursion", false, "Do not recurse through sub-directories"); recurse.setRequired(false); result.addOption(recurse); Option nodata = new Option("nd", "nodata", true, "override nodata value"); //nodata.setArgPattern(argPattern, limit); nodata.setRequired(false); result.addOption(nodata); Option tags = new Option("t", "tags", true, "tags (fmt: \"k1,v:k2,v:...\""); tags.setRequired(false); result.addOption(tags); Option notags = new Option("nt", "notags", false, "Do not automatically load tags from source images"); notags.setRequired(false); result.addOption(notags); OptionGroup aggregators = new OptionGroup(); Option mean = new Option("m", "mean", false, "Mean (Average) Pyramid Pixel Resampling Method"); mean.setRequired(false); aggregators.addOption(mean); Option sum = new Option("s", "sum", false, "Summing Pyramid Pixel Resampling Method"); sum.setRequired(false); aggregators.addOption(sum); Option nearest = new Option("n", "nearest", false, "Nearest Pyramid Pixel Resampling Method"); nearest.setRequired(false); aggregators.addOption(nearest); Option min = new Option("min", "minimum", false, "Minimum Pyramid Pixel Resampling Method"); min.setRequired(false); aggregators.addOption(min); Option max = new Option("max", "maximum", false, "Maximum Pyramid Pixel Resampling Method"); max.setRequired(false); aggregators.addOption(max); Option minavgpair = new Option("minavgpair", "miminumaveragepair", false, "Minimum Average Pair Pyramid Pixel Resampling Method"); minavgpair.setRequired(false); aggregators.addOption(minavgpair); result.addOptionGroup(aggregators); Option local = new Option("lc", "local", false, "Use local files for ingest, good for small ingests"); local.setRequired(false); result.addOption(local); Option quick = new Option("q", "quick", false, "Quick ingest (for small files only)"); quick.setRequired(false); result.addOption(quick); Option zoom = new Option("z", "zoom", true, "force zoom level"); zoom.setRequired(false); result.addOption(zoom); Option skippre = new Option("sk", "skippreprocessing", false, "Skip the preprocessing step (must specify zoom)"); skippre.setRequired(false); result.addOption(skippre); Option protectionLevelOption = new Option("pl", "protectionLevel", true, "Protection level"); // If mrgeo.conf security.classification.required is true and there is no // security.classification.default, then the security classification // argument is required, otherwise it is not. Properties props = MrGeoProperties.getInstance(); String protectionLevelRequired = props.getProperty(MrGeoConstants.MRGEO_PROTECTION_LEVEL_REQUIRED, "false") .trim(); String protectionLevelDefault = props.getProperty(MrGeoConstants.MRGEO_PROTECTION_LEVEL_DEFAULT, ""); if (protectionLevelRequired.equalsIgnoreCase("true") && protectionLevelDefault.isEmpty()) { protectionLevelOption.setRequired(true); } else { protectionLevelOption.setRequired(false); } result.addOption(protectionLevelOption); return result; }