List of usage examples for org.apache.commons.cli OptionBuilder hasArg
public static OptionBuilder hasArg(boolean hasArg)
hasArg
is true. From source file:gov.llnl.lc.smt.command.system.SmtSystem.java
/** * Describe the method here//w ww .java2s . c o m * * @see gov.llnl.lc.smt.command.SmtCommand#init() * @see gov.llnl.lc.smt.command.SmtCommand#initCommonOptions() * * @return ***********************************************************/ @Override public boolean init() { USAGE = "[-h=<host url>] [-pn=<port num>] [<sys guid>] -sr"; HEADER = "smt-system - a tool for obtaining high level system information"; EXAMPLE = "examples:" + SmtConstants.NEW_LINE + "> smt-system -pn 10011 - using the default port, list any & all systems" + SmtConstants.NEW_LINE + "> smt-system -ql - list the query options" + SmtConstants.NEW_LINE + "> smt-system -pn 10011 0006:6a00:e900:131d -q switches\n" + ". - list the switches associated with the system" + SmtConstants.NEW_LINE + "> smt-system 0006:6a00:e900:131e -q ports\n" + ". - show the port arrangement for the system" + SmtConstants.NEW_LINE + "> smt-system -pn 10013 -dump - show the systems (if any) in a verbose way" + SmtConstants.NEW_LINE + "."; // terminate with nl // create and initialize the common options for this command initCommonOptions(); SmtProperty sp = SmtProperty.SMT_QUERY_TYPE; Option qType = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_QUERY_LIST; Option qList = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_DUMP; Option dump = OptionBuilder.hasOptionalArg().withDescription(sp.getDescription()).withLongOpt(sp.getName()) .create(sp.getShortName()); sp = SmtProperty.SMT_STATUS; Option status = OptionBuilder.hasArg(false).withDescription(sp.getDescription()).withLongOpt(sp.getName()) .create(sp.getShortName()); options.addOption(status); options.addOption(qType); options.addOption(qList); options.addOption(dump); return true; }
From source file:gov.llnl.lc.smt.command.SmtCommand.java
/** * All the options that are common to all SMT commands. This method should be * included within every init() method, near the top. * /*ww w. j a v a 2 s . c o m*/ * @see describe related java objects * * @return ***********************************************************/ protected boolean initConnectionOptions() { // create and initialize the common options for most commands initMinimumOptions(); SmtProperty sp = SmtProperty.SMT_HOST; Option host_name = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()) .withValueSeparator('=').withDescription(sp.getDescription()).withLongOpt(sp.getName()) .create(sp.getShortName()); sp = SmtProperty.SMT_PORT; Option port_num = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_REUSE; Option re_use = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); options.addOption(host_name); options.addOption(port_num); options.addOption(re_use); return true; }
From source file:gov.llnl.lc.smt.command.config.SmtConfig.java
@Override public boolean init() { USAGE = "smt-config [-rC <filename>] [-wC <filename>] [-lp]"; HEADER = "smt-config - a tool for reading, writing, and parsing SMT Configuration settings"; EXAMPLE = "examples:" + SmtConstants.NEW_LINE + "> smt-config -rC %h/.smt/config.file -lp - read and list the contents of config.file" + SmtConstants.NEW_LINE/* ww w. j a v a2 s .co m*/ + "> smt-config -wC newConfig.file - write current configuration to newConfig.file" + SmtConstants.NEW_LINE + "."; // terminate with nl // create and initialize the minimum options for this command // initCommonOptions(); initMinimumOptions(); SmtProperty sp = SmtProperty.SMT_LIST; Option list = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_WRITE_CONFIG; Option wFile = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); options.addOption(wFile); options.addOption(list); return false; }
From source file:gov.llnl.lc.smt.command.SmtCommand.java
/** * All the options necessary for playback control (the time * slider)/* www. j a v a 2s.c om*/ * * @see describe related java objects * * @return ***********************************************************/ protected boolean initPlayableOptions() { // create and initialize the common options for playback SmtProperty sp = SmtProperty.SMT_UPDATE_PERIOD; Option uPeriod = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_UPDATE_MULTIPLIER; Option multi = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_WRAP_DATA; Option wrap = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_SINGLE_SHOT; Option once = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_PLAY_CONTROL; Option play = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); options.addOption(uPeriod); options.addOption(multi); options.addOption(wrap); options.addOption(once); options.addOption(play); return true; }
From source file:gov.llnl.lc.smt.command.port.SmtPort.java
/** * Describe the method here// www. j a va 2 s . co m * * @see gov.llnl.lc.smt.command.SmtCommand#init() * * @return ***********************************************************/ @Override public boolean init() { USAGE = "[-h=<host url>] [-pn=<port num>] <node: guid, lid, or name> <port #>"; HEADER = "smt-port - Get port information"; EXAMPLE = "examples:" + SmtConstants.NEW_LINE + "> smt-port -pn 10011 - provide a summary of ports in the fabric" + SmtConstants.NEW_LINE + "> smt-port -pn 10013 -q status 14 3 - show the attributes of port 3 of node with lid 14" + SmtConstants.NEW_LINE + "> smt-port -pn 10011 14 3 - show port counters for the lid 14 and port number 3" + SmtConstants.NEW_LINE + "> smt-port -q counters -pn 10013 14 3 - same as above" + SmtConstants.NEW_LINE + "> smt-port -pn 10013 14 3 -q errors - similar to above, but only show error counters" + SmtConstants.NEW_LINE + "> smt-port -q route ibcore1 L113 24 - using the switches name, show the routes through port 24" + SmtConstants.NEW_LINE + "> smt-port -q speed EDR - show all of the EDR ports" + SmtConstants.NEW_LINE + "> smt-port -rH surface3h.his -dump - dump all information about all the ports" + SmtConstants.NEW_LINE + "."; // terminate with nl // create and initialize the common options for this command initCommonOptions(); // initialize the command specific options SmtProperty sp = SmtProperty.SMT_QUERY_TYPE; Option qType = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_QUERY_LIST; Option qList = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_STATUS; Option status = OptionBuilder.hasArg(false).withDescription(sp.getDescription()).withLongOpt(sp.getName()) .create(sp.getShortName()); sp = SmtProperty.SMT_DUMP; Option dump = OptionBuilder.hasArg(false).withDescription(sp.getDescription()).withLongOpt(sp.getName()) .create(sp.getShortName()); options.addOption(qType); options.addOption(qList); options.addOption(status); options.addOption(dump); return true; }
From source file:gov.llnl.lc.smt.command.fabric.SmtFabric.java
/** * Describe the method here//w ww . j a v a 2 s .c om * * @see gov.llnl.lc.smt.command.SmtCommand#init() * @see gov.llnl.lc.smt.command.SmtCommand#initCommonOptions() * * @return ***********************************************************/ @Override public boolean init() { USAGE = "[-h=<host url>] [-pn=<port num>] -sr"; HEADER = "smt-fabric - a tool for obtaining high level fabric information"; EXAMPLE = "examples:" + SmtConstants.NEW_LINE + "> smt-fabric -ql - list the query options" + SmtConstants.NEW_LINE + "> smt-fabric -dF 3 - starting at port 10011, and for the next 3 ports, attempt to find an OMS and report" + SmtConstants.NEW_LINE + "> smt-fabric -pn 10011 -q switches - list all the switches in the fabric" + SmtConstants.NEW_LINE + "> smt-fabric -rH surface3.his -q check - using the history file, perform a fabric check" + SmtConstants.NEW_LINE + "> smt-fabric -pn 10013 -sr - provide a status report for the fabric on port 10013" + SmtConstants.NEW_LINE + "."; // terminate with nl // create and initialize the common options for this command initCommonOptions(); SmtProperty sp = SmtProperty.SMT_QUERY_TYPE; Option qType = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_QUERY_LIST; Option qList = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_FABRIC_CONFIG_CMD; Option fConfig = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_NODE_MAP_CMD; Option nMap = new Option(sp.getShortName(), sp.getName(), false, sp.getDescription()); sp = SmtProperty.SMT_FABRIC_DISCOVER; Option discover = OptionBuilder.hasArg(true).hasArgs(1).withArgName(sp.getArgName()).withValueSeparator('=') .withDescription(sp.getDescription()).withLongOpt(sp.getName()).create(sp.getShortName()); sp = SmtProperty.SMT_STATUS; Option status = OptionBuilder.hasArg(false).withDescription(sp.getDescription()).withLongOpt(sp.getName()) .create(sp.getShortName()); options.addOption(status); options.addOption(qType); options.addOption(qList); options.addOption(discover); options.addOption(fConfig); options.addOption(nMap); return true; }
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 a v a2 s. 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:nl.strohalm.cyclos.setup.Arguments.java
static Options buildOptions(final Locale locale) { final ResourceBundle bundle = Setup.getResourceBundle(locale); final Options options = new Options(); // help/*w w w .j a v a 2s .c om*/ OptionBuilder.withLongOpt("help"); OptionBuilder.hasArg(false); OptionBuilder.withDescription(bundle.getString("arg.help")); options.addOption(OptionBuilder.create('?')); // force OptionBuilder.withLongOpt("force"); OptionBuilder.hasArg(false); OptionBuilder.withDescription(bundle.getString("arg.force")); options.addOption(OptionBuilder.create('f')); // create database OptionBuilder.withLongOpt("database"); OptionBuilder.hasArg(false); OptionBuilder.withDescription(bundle.getString("arg.create-data-base")); options.addOption(OptionBuilder.create('d')); // export script OptionBuilder.withLongOpt("script"); OptionBuilder.hasOptionalArg(); OptionBuilder.withArgName("file"); OptionBuilder.withDescription(bundle.getString("arg.export-script")); options.addOption(OptionBuilder.create('s')); // create basic data OptionBuilder.withLongOpt("basic-data"); OptionBuilder.hasArg(false); OptionBuilder.withDescription(bundle.getString("arg.create-basic-data")); options.addOption(OptionBuilder.create('b')); // create initial data OptionBuilder.withLongOpt("initial-data"); OptionBuilder.hasArg(false); OptionBuilder.withDescription(bundle.getString("arg.create-initial-data")); options.addOption(OptionBuilder.create('i')); // create sms data OptionBuilder.withLongOpt("sms-data"); OptionBuilder.hasArg(false); OptionBuilder.withDescription(bundle.getString("arg.create-sms-data")); options.addOption(OptionBuilder.create('m')); return options; }
From source file:org.apache.avro.tool.TetherTool.java
@Override public int run(InputStream ins, PrintStream outs, PrintStream err, List<String> args) throws Exception { String[] argarry = args.toArray(new String[0]); Options opts = new Options(); Option helpopt = OptionBuilder.hasArg(false).withDescription("print this message").create("help"); Option inopt = OptionBuilder.hasArg().isRequired().withDescription("comma-separated input paths") .create("in"); Option outopt = OptionBuilder.hasArg().isRequired().withDescription("The output path.").create("out"); Option pargs = OptionBuilder.hasArg().withDescription( "A string containing the command line arguments to pass to the tethered process. String should be enclosed in quotes") .create("exec_args"); Option popt = OptionBuilder.hasArg().isRequired().withDescription("executable program, usually in HDFS") .create("program"); Option outscopt = OptionBuilder.withType(File.class).hasArg().isRequired() .withDescription("schema file for output of reducer").create("outschema"); Option outscmapopt = OptionBuilder.withType(File.class).hasArg() .withDescription("(optional) map output schema file, if different from outschema") .create("outschemamap"); Option redopt = OptionBuilder.withType(Integer.class).hasArg() .withDescription("(optional) number of reducers").create("reduces"); Option cacheopt = OptionBuilder.withType(Boolean.class).hasArg().withDescription( "(optional) boolean indicating whether or not the exectuable should be distributed via distributed cache") .create("exec_cached"); Option protoopt = OptionBuilder.hasArg() .withDescription("(optional) specifies the transport protocol 'http' or 'sasl'").create("protocol"); opts.addOption(redopt);//from w ww.ja v a 2 s . c om opts.addOption(outscopt); opts.addOption(popt); opts.addOption(pargs); opts.addOption(inopt); opts.addOption(outopt); opts.addOption(helpopt); opts.addOption(outscmapopt); opts.addOption(cacheopt); opts.addOption(protoopt); CommandLineParser parser = new GnuParser(); String[] genargs = null; CommandLine line = null; HelpFormatter formatter = new HelpFormatter(); JobConf job = new JobConf(); try { line = parser.parse(opts, argarry); if (line.hasOption("help")) { formatter.printHelp("tether", opts); return 0; } genargs = line.getArgs(); FileInputFormat.addInputPaths(job, line.getOptionValue("in")); FileOutputFormat.setOutputPath(job, new Path(line.getOptionValue("out"))); List<String> exargs = null; Boolean cached = false; if (line.hasOption("exec_args")) { String[] splitargs = line.getOptionValue("exec_args").split(" "); exargs = new ArrayList<String>(); for (String item : splitargs) { exargs.add(item); } } if (line.hasOption("exec_cached")) { cached = Boolean.parseBoolean(line.getOptionValue("exec_cached")); } TetherJob.setExecutable(job, new File(line.getOptionValue("program")), exargs, cached); File outschema = (File) line.getParsedOptionValue("outschema"); job.set(AvroJob.OUTPUT_SCHEMA, Schema.parse(outschema).toString()); if (line.hasOption("outschemamap")) { job.set(AvroJob.MAP_OUTPUT_SCHEMA, Schema.parse((File) line.getParsedOptionValue("outschemamap")).toString()); } if (line.hasOption("reduces")) { job.setNumReduceTasks((Integer) line.getParsedOptionValue("reduces")); } if (line.hasOption("protocol")) { TetherJob.setProtocol(job, line.getOptionValue("protocol")); } } catch (Exception exp) { System.out.println("Unexpected exception: " + exp.getMessage()); formatter.printHelp("tether", opts); return -1; } TetherJob.runJob(job); return 0; }
From source file:org.apache.openejb.config.EffectiveTomEEXml.java
private static CommandLine parseCommand(final String[] args) throws SystemExitException { final Options options = new Options(); options.addOption(OptionBuilder.hasArg(true).withLongOpt("path").withDescription("[openejb|tomee].xml path") .create("p")); final CommandLine line; try {/*from w w w . j ava 2 s . co m*/ line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return null; } return line; }