List of usage examples for org.apache.commons.cli OptionGroup OptionGroup
OptionGroup
From source file:edu.cornell.med.icb.R.RUtils.java
public static void main(final String[] args) throws ParseException, ConfigurationException { final Options options = new Options(); final Option helpOption = new Option("h", "help", false, "Print this message"); options.addOption(helpOption);//w w w . ja v a 2 s . c o m final Option startupOption = new Option(Mode.startup.name(), Mode.startup.name(), false, "Start Rserve process"); final Option shutdownOption = new Option(Mode.shutdown.name(), Mode.shutdown.name(), false, "Shutdown Rserve process"); final Option validateOption = new Option(Mode.validate.name(), Mode.validate.name(), false, "Validate that Rserve processes are running"); final OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(startupOption); optionGroup.addOption(shutdownOption); optionGroup.addOption(validateOption); optionGroup.setRequired(true); options.addOptionGroup(optionGroup); final Option portOption = new Option("port", "port", true, "Use specified port to communicate with the Rserve process"); portOption.setArgName("port"); portOption.setType(int.class); options.addOption(portOption); final Option hostOption = new Option("host", "host", true, "Communicate with the Rserve process on the given host"); hostOption.setArgName("hostname"); hostOption.setType(String.class); options.addOption(hostOption); final Option userOption = new Option("u", "username", true, "Username to send to the Rserve process"); userOption.setArgName("username"); userOption.setType(String.class); options.addOption(userOption); final Option passwordOption = new Option("p", "password", true, "Password to send to the Rserve process"); passwordOption.setArgName("password"); passwordOption.setType(String.class); options.addOption(passwordOption); final Option configurationOption = new Option("c", "configuration", true, "Configuration file or url to read from"); configurationOption.setArgName("configuration"); configurationOption.setType(String.class); options.addOption(configurationOption); final Parser parser = new BasicParser(); final CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException e) { usage(options); throw e; } int exitStatus = 0; if (commandLine.hasOption("h")) { usage(options); } else { Mode mode = null; for (final Mode potentialMode : Mode.values()) { if (commandLine.hasOption(potentialMode.name())) { mode = potentialMode; break; } } final ExecutorService threadPool = Executors.newCachedThreadPool(); if (commandLine.hasOption("configuration")) { final String configurationFile = commandLine.getOptionValue("configuration"); LOG.info("Reading configuration from " + configurationFile); XMLConfiguration configuration; try { final URL configurationURL = new URL(configurationFile); configuration = new XMLConfiguration(configurationURL); } catch (MalformedURLException e) { // resource is not a URL: attempt to get the resource from a file LOG.debug("Configuration is not a valid url"); configuration = new XMLConfiguration(configurationFile); } configuration.setValidating(true); final int numberOfRServers = configuration.getMaxIndex("RConfiguration.RServer") + 1; boolean failed = false; for (int i = 0; i < numberOfRServers; i++) { final String server = "RConfiguration.RServer(" + i + ")"; final String host = configuration.getString(server + "[@host]"); final int port = configuration.getInt(server + "[@port]", RConfigurationUtils.DEFAULT_RSERVE_PORT); final String username = configuration.getString(server + "[@username]"); final String password = configuration.getString(server + "[@password]"); final String command = configuration.getString(server + "[@command]", DEFAULT_RSERVE_COMMAND); if (executeMode(mode, threadPool, host, port, username, password, command) != 0) { failed = true; // we have other hosts to check so keep a failed state } } if (failed) { exitStatus = 3; } } else { final String host = commandLine.getOptionValue("host", "localhost"); final int port = Integer.valueOf(commandLine.getOptionValue("port", "6311")); final String username = commandLine.getOptionValue("username"); final String password = commandLine.getOptionValue("password"); exitStatus = executeMode(mode, threadPool, host, port, username, password, null); } threadPool.shutdown(); } System.exit(exitStatus); }
From source file:cz.muni.fi.crocs.JeeTool.OptionsMain.java
public static Options createOptions() { Option help = new Option("h", "help", false, "show help and exit"); Option motes = new Option("a", "motes", true, "path to alternative file of motes, default setting is stored in /opt/motePaths.txt"); Option ids = new Option("i", "id", true, "select IDs of nodes from motelist, use comma separated list of IDs or ID ranges, such as 1,3,5-7,9-15"); Option detect = new Option("d", "detect", false, "Perform node detection only"); Option verbose = new Option("v", "verbose", false, "show extended text output"); Option silent = new Option("s", "silent", false, "show limited text output"); OptionGroup output = new OptionGroup(); output.addOption(verbose);/* w ww .j a v a 2 s .c om*/ output.addOption(silent); Option make = new Option("m", "make", true, "make target at this path, .ino file required"); Option makeUpload = new Option("u", "make_upload", true, "make target at this path and upload to nodes, .ino file required"); Option threads = new Option("t", "threads", false, "use threads for paralell upload"); OptionGroup makeGroup = new OptionGroup(); makeGroup.addOption(make); makeGroup.addOption(makeUpload); Options options = new Options(); options.addOption(help); options.addOption(motes); options.addOption(ids); options.addOption(detect); options.addOptionGroup(output); options.addOptionGroup(makeGroup); options.addOption(threads); return options; }
From source file:cz.muni.fi.crocs.EduHoc.OptionsMain.java
public static Options createOptions() { Option help = new Option("h", "help", false, "show help and exit"); Option motes = new Option("a", "motes", true, "path to alternative file of motes, default setting is stored in confix/motePaths.txt"); Option ids = new Option("i", "id", true, "select IDs of nodes from motelist, use comma separated list of IDs or ID ranges, such as 1,3,5-7,9-15"); Option detect = new Option("d", "detect", false, "Perform node detection only"); Option verbose = new Option("v", "verbose", false, "show extended text output"); Option silent = new Option("s", "silent", false, "show limited text output"); OptionGroup output = new OptionGroup(); output.addOption(verbose);//from w ww .j av a2s.c o m output.addOption(silent); Option make = new Option("m", "make", true, "make target at this path, directory must contain Makefile"); Option makeClean = new Option("c", "make_clean", true, "make clean target at this path, directory must contain Makefile"); Option makeUpload = new Option("u", "make_upload", true, "make target at this path and upload to nodes, directory must contain Makefile"); Option threads = new Option("t", "threads", false, "use threads for paralell upload"); OptionGroup makeGroup = new OptionGroup(); makeGroup.addOption(make); makeGroup.addOption(makeUpload); makeGroup.addOption(makeClean); Option listen = new Option("l", "listen", true, "connect to serial and save stream to files, set path to directory for files"); Option write = new Option("w", "write", true, "write to serial now or after upload, directory must contain at least one file with same name as node"); Option execute = new Option("E", "execute", true, "path to shell script to be executed in phase 3"); Option time = new Option("T", "time", true, "countdown in minutes for serial phase, default is 15 minutes, after this time, serial connection closes"); time.setType(int.class); Options options = new Options(); options.addOption(help); options.addOption(motes); options.addOption(ids); options.addOption(detect); options.addOptionGroup(output); options.addOptionGroup(makeGroup); options.addOption(threads); options.addOption(write); options.addOption(listen); options.addOption(execute); options.addOption(time); return options; }
From source file:com.ericsson.eiffel.remrem.generate.cli.CLIOptions.java
/** * Creates the options needed by command line interface * /*from www . j a v a 2 s . c o m*/ * @return the options this CLI can handle */ public static Options createCLIOptions() { options = new Options(); typeGroup = new OptionGroup(); Option msgTypeOpt = new Option("t", "message_type", true, "message type"); typeGroup.addOption(msgTypeOpt); options.addOptionGroup(typeGroup); options.addOption("h", "help", false, "show help."); options.addOption("r", "response_file", true, "file to store the response in, optional"); options.addOption("d", "debug", false, "enable debug traces"); options.addOption("mp", "messaging_protocol", true, "name of messaging protocol to be used, e.g. eiffel3, eiffelsemantics"); contentGroup = new OptionGroup(); contentGroup.addOption(new Option("f", "content_file", true, "message content file")); contentGroup.addOption(new Option("json", "json_content", true, "json content")); options.addOptionGroup(contentGroup); options.addOption("v", "list_versions", false, "lists the versions of generate and all loaded protocols"); return options; }
From source file:edu.cmu.tetrad.cli.CausalCmdApplication.java
private static void populateMainOptions() { OptionGroup optGrp = new OptionGroup(); optGrp.addOption(new Option(null, ALGO_OPT, true, algorithmCmd())); optGrp.addOption(new Option(null, SIM_DATA_OPT, true, simulationCmd())); optGrp.setRequired(true);//w ww . j av a2s.c om MAIN_OPTIONS.addOptionGroup(optGrp); MAIN_OPTIONS.addOption(null, VERSION_OPT, false, "Version."); }
From source file:com.nokia.tools.vct.cli.CommandLineUtils.java
public static void initOptions(Options options) { IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtension[] extensions = registry.getExtensionPoint(EXTENSION_NAMESPACE).getExtensions(); for (IExtension extension : extensions) { for (IConfigurationElement element : extension.getConfigurationElements()) { if (ELEMENT_OPTION.equals(element.getName())) { Option option = makeOption(element); options.addOption(option); } else if (ELEMENT_OPTION_GROUP.equals(element.getName())) { OptionGroup optionGroup = new OptionGroup(); boolean required = Boolean.TRUE.equals(element.getAttribute(OPTION_GROUP_ATTR_REQUIRED)); optionGroup.setRequired(required); for (IConfigurationElement element2 : element.getChildren(ELEMENT_OPTION)) { Option option = makeOption(element2); optionGroup.addOption(option); }/* w ww .j ava 2s.com*/ options.addOptionGroup(optionGroup); } } } }
From source file:com.momab.dstool.DSTool.java
static Options commandLineOptions() { Option help = new Option("h", "help", false, "print this message"); Option username = new Option("u", "username", true, "Username to use when sending requests to the remote app"); Option password = new Option("p", "password", true, "Password to use when sending requests to the remote app"); Option port = new Option("P", "port", true, "Network port used when connecting to the app, if omitted the default port 80 wil be used"); Option read = new Option("r", "read", false, "download all entites of the specified kind from the" + "remote app datastore"); Option write = new Option("w", "write", false, "upload entites of the specified kind to the remote" + " app datastore"); Option delete = new Option("d", "delete", false, "delete all entities of the specified kind from the remote" + " app datastore"); Option file = new Option("f", "file", true, "specify a file name to read/write local entity data from/to" + ", stdin/stdout will be used of the filename is omitted"); OptionGroup operations = new OptionGroup(); operations.addOption(read);// w ww . j ava2s . co m operations.addOption(write); operations.addOption(delete); Options options = new Options(); options.addOptionGroup(operations); options.addOption(file); options.addOption(help); options.addOption(username); options.addOption(password); options.addOption(port); return options; }
From source file:com.tvh.gmaildrafter.Drafter.java
private static Options getCMDLineOptions() { /*//w w w. j a v a 2 s. c o m * Create the command line options */ Options options = new Options(); options.addOption(new Option("h", "help", false, "Show this help message.")); OptionGroup body = new OptionGroup(); body.addOption(new Option("i", "stdin", false, "Read body text from stdin.")); body.addOption(OptionBuilder.withLongOpt("body").withArgName("filename").hasArg() .withDescription("File containing the body text").create("b")); options.addOptionGroup(body); options.addOption(OptionBuilder.withLongOpt("username").hasArg().withArgName("email address") .withDescription("Your Google Email adress.").create()); options.addOption(OptionBuilder.withLongOpt("password").hasArg().withArgName("google password") .withDescription( "Your Google password (caution: providing this on the commandline can be a security problem).") .create()); options.addOption(OptionBuilder.withLongOpt("subject").withArgName("text").hasArg() .withDescription("Subject of the mail").create("s")); options.addOption(OptionBuilder.withLongOpt("subjectfile").withArgName("filename").hasArg() .withDescription("File containing the subject of the mail (UTF-8)").create()); options.addOption(OptionBuilder.withLongOpt("attachments").hasArgs().withArgName("filename,filename,...") .withValueSeparator(',').withDescription("Attachments").create("a")); options.addOption( OptionBuilder.withLongOpt("attachmentnames").hasArgs().withArgName("filename,filename,...") .withValueSeparator(',').withDescription("Attachment names").create("n")); options.addOption(OptionBuilder.withLongOpt("to").hasArgs().withArgName("foo@bar.com,oof@rab.com,...") .withValueSeparator(',').withDescription("destination").create("t")); options.addOption(new Option("d", "deletebody", false, "Delete bodyfile after sending.")); options.addOption(new Option(null, "deletesubjectfile", false, "Delete subjectfile after sending.")); options.addOption(new Option(null, "immediate", false, "Immediately send, don't open draft first.")); options.addOption(OptionBuilder.withLongOpt("cc").hasArgs().withArgName("foo@bar1.com,foo@rba.com") .withValueSeparator(',').withDescription("cc").create("c")); options.addOption(OptionBuilder.withLongOpt("bcc").hasArgs().withArgName("foo@bar2.com,ofo@bar.com") .withValueSeparator(',').withDescription("bcc").create()); return options; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ResultFileInfo.java
@SuppressWarnings("static-access") @Override// www. j a v a 2 s . c om public Options getOptions() { Options options = super.getOptions(); OptionGroup group = new OptionGroup(); group.setRequired(true); group.addOption(OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").create('b')); group.addOption(OptionBuilder.withLongOpt("dimension").hasArg().withArgName("number").create('d')); options.addOptionGroup(group); options.addOption(OptionBuilder.withLongOpt("output").hasArg().withArgName("file").create('o')); return options; }
From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilder.java
public static Options buildPa11yOptions() { Options options = new Options(); OptionGroup mutuallyExclusiveOptions = new OptionGroup(); mutuallyExclusiveOptions.addOption(getCreateTaskOption()); mutuallyExclusiveOptions.addOption(getListTasksOption()); mutuallyExclusiveOptions.addOption(getRunOption()); mutuallyExclusiveOptions.addOption(getRetrieveTaskOption()); mutuallyExclusiveOptions.addOption(getDeleteTaskOption()); options.addOptionGroup(mutuallyExclusiveOptions); options.addOption(getNameOption());/*from w ww . j a va 2 s . c o m*/ options.addOption(getUrlOption()); options.addOption(getStandardOption()); options.addOption(getLastResultOption()); options.addOption(getTaskIdOption()); return options; }