List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:com.aerospike.osm.Around.java
private static Parameters parseParameters(String[] args) throws ParseException { Parameters params = new Parameters(); Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: localhost)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("U", "user", true, "User name"); options.addOption("P", "password", true, "Password"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set name (default: osm)"); options.addOption("r", "radius", true, "Radius in meters (default: 2000.0)"); options.addOption("a", "amenity", true, "Filter by amenity"); options.addOption("u", "usage", false, "Print usage"); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); params.host = cl.getOptionValue("h", "localhost"); String portString = cl.getOptionValue("p", "3000"); params.port = Integer.parseInt(portString); params.user = cl.getOptionValue("U"); params.password = cl.getOptionValue("P"); params.namespace = cl.getOptionValue("n", "test"); params.set = cl.getOptionValue("s", "osm"); String radiusString = cl.getOptionValue("r", "2000"); params.radius = Double.parseDouble(radiusString); params.amenity = cl.getOptionValue("a"); if (cl.hasOption("u")) { usage(options);/*from w w w .j a v a 2 s .c o m*/ System.exit(0); } String[] latlng = cl.getArgs(); if (latlng.length != 2) { System.out.println("missing latitude and longitude parameters"); usage(options); System.exit(1); } params.lat = Double.parseDouble(latlng[0]); params.lng = Double.parseDouble(latlng[1]); return params; }
From source file:com.aerospike.yelp.Around.java
private static Parameters parseParameters(String[] args) throws ParseException { Parameters params = new Parameters(); Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: localhost)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("U", "user", true, "User name"); options.addOption("P", "password", true, "Password"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set name (default: yelp)"); options.addOption("r", "radius", true, "Radius in meters (default: 2000.0)"); options.addOption("c", "category", true, "Filter by category"); options.addOption("u", "usage", false, "Print usage"); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); params.host = cl.getOptionValue("h", "localhost"); String portString = cl.getOptionValue("p", "3000"); params.port = Integer.parseInt(portString); params.user = cl.getOptionValue("U"); params.password = cl.getOptionValue("P"); params.namespace = cl.getOptionValue("n", "test"); params.set = cl.getOptionValue("s", "yelp"); String radiusString = cl.getOptionValue("r", "2000"); params.radius = Double.parseDouble(radiusString); params.category = cl.getOptionValue("c"); if (cl.hasOption("u")) { usage(options);//from w ww. ja v a 2 s . com System.exit(0); } String[] latlng = cl.getArgs(); if (latlng.length != 2) { System.out.println("missing latitude and longitude parameters"); usage(options); System.exit(1); } params.lat = Double.parseDouble(latlng[0]); params.lng = Double.parseDouble(latlng[1]); return params; }
From source file:com.galenframework.actions.GalenActionDumpArguments.java
public static GalenActionDumpArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("u", "url", true, "Initial test url"); options.addOption("s", "size", true, "Browser window size"); options.addOption("W", "max-width", true, "Maximum width of element area image"); options.addOption("H", "max-height", true, "Maximum height of element area image"); options.addOption("E", "export", true, "Export path for page dump"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try {//w ww.ja v a 2 s .c o m cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } GalenActionDumpArguments arguments = new GalenActionDumpArguments(); arguments.setUrl(cmd.getOptionValue("u")); arguments.setScreenSize(convertScreenSize(cmd.getOptionValue("s"))); arguments.setMaxWidth(parseOptionalInt(cmd.getOptionValue("W"))); arguments.setMaxHeight(parseOptionalInt(cmd.getOptionValue("H"))); arguments.setExport(cmd.getOptionValue("E")); String[] leftovers = cmd.getArgs(); List<String> paths = new LinkedList<String>(); if (leftovers.length > 0) { for (int i = 0; i < leftovers.length; i++) { paths.add(leftovers[i]); } } arguments.setPaths(paths); return arguments; }
From source file:de.rub.syssec.saaf.Main.java
/** * Parses the commandline and sets config parameters accordingly. * //from w w w . ja v a 2s. c o m * @param args * @return * @throws ParseException */ private static void processCommandline(String[] args) throws ParseException { CommandLineParser parser = new PosixParser(); CommandLine cmdLine = null; apkPath = null; try { cmdLine = parser.parse(options, args); } catch (UnrecognizedOptionException e) { System.out.println("Found an unrecognized option( " + e.getMessage() + " ), the following possibilities are supported: "); usage(); exit(); } String[] remainingArgs = cmdLine.getArgs(); switch (remainingArgs.length) { case 0: apkPath = null; break; case 1: apkPath = new File(remainingArgs[0]); break; default: LOGGER.error("You can't insert more than one Path!"); for (int i = 0; i < remainingArgs.length; i++) { System.err.print("Unknown arguments: " + remainingArgs[i] + "\n"); } usage(true); exit(); } if (cmdLine.hasOption(props.getProperty("options.version.short"))) { version(); exit(); } if (cmdLine.hasOption(props.getProperty("options.help.short"))) { usage(); exit(); } if (cmdLine.hasOption(props.getProperty("options.nobt.short")) && cmdLine.hasOption(props.getProperty("options.noheuristic.short"))) { LOGGER.error("You diabled quick checks as well as program slicing, this is currently not supported."); // usage(); exit(); } parseOptions(cmdLine); }
From source file:com.subakva.formicid.Main.java
protected static void runScript(final String scriptName, final String command, final CommandLine cli) { Context.call(new ContextAction() { public Object run(Context cx) { try { ScriptableObject global = cx.initStandardObjects(); Container container = new Container(global); NativeObject formicid = new NativeObject(); container.setLogLevel(getLogLevel(cli)); formicid.put("global", formicid, global); formicid.put("logLevel", formicid, getLogLevel(cli)); global.put("formicid", global, formicid); evaluateResource(cx, global, "formicid.js"); defineTasks(container);/*from www . ja v a 2 s.co m*/ cx.evaluateReader(global, new FileReader(scriptName), scriptName, 1, null); String array = toArrayString(cli.getArgs()); String script = "formicid.start('" + command + "', " + array + ");"; cx.evaluateString(global, script, "Main.runScript", 1, null); return global; } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }); }
From source file:dap4.dap4.Dap4Print.java
static CommandlineOptions getopts(String[] argv) { // Get command line options Options options = new Options(); options.addOption("o", true, "send output to this file"); CommandLineParser clparser = new PosixParser(); CommandLine cmd = null; try {/*from w w w . j a v a 2s .co m*/ cmd = clparser.parse(options, argv); } catch (ParseException pe) { usage("Command line parse failure: " + pe.getMessage()); } CommandlineOptions cloptions = new CommandlineOptions(); String[] remainder = cmd.getArgs(); if (remainder.length > 0) cloptions.path = remainder[0]; if (cmd.hasOption("o")) { cloptions.outputfile = cmd.getOptionValue("o"); } return cloptions; }
From source file:languageTools.Analyzer.java
private static File parseOptions(String[] args) throws ParseException { CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); lexer = cmd.hasOption(OPTION_LEXER); program = cmd.hasOption(OPTION_PROGRAM); masFile = cmd.hasOption(OPTION_MAS); agentFile = cmd.hasOption(OPTION_GOAL); moduleFile = cmd.hasOption(OPTION_MOD2G); recursive = cmd.hasOption(OPTION_RECURSIVE); /*//from ww w . j a v a 2 s . c o m * Handle general options. */ if (cmd.hasOption(OPTION_HELP)) { throw new ParseException("The GOAL Grammar Tools. Copyright (C) 2014 GPLv3"); } if (cmd.hasOption(OPTION_LICENSE)) { showLicense(); throw new ParseException(""); } // Process remaining arguments if (cmd.getArgs().length == 0) { throw new ParseException("Missing file or directory"); } if (cmd.getArgs().length > 1) { throw new ParseException("Expected single file or directory name but got: " + cmd.getArgs()); } // Check existence of file File file = new File(cmd.getArgs()[0]); if (!file.exists()) { throw new ParseException("Could not find " + file); } return file; }
From source file:com.opengamma.bbg.loader.BloombergHistoricalLoader.java
private static void configureOptions(Options options, CommandLine line, BloombergHistoricalLoader dataLoader) { //get files from command line if any String[] files = line.getArgs(); dataLoader.setFiles(Arrays.asList(files)); if (line.hasOption(UPDATE_OPTION)) { dataLoader.setUpdateDb(true);//from ww w . ja v a2 s .c o m } if (line.hasOption(POSITION_MASTER_OPTION)) { dataLoader.setLoadPositionMaster(true); } if (line.hasOption(RELOAD_OPTION)) { dataLoader.setReload(true); } if (line.hasOption(CSV_OPTION)) { dataLoader.setCsv(true); } if (line.hasOption(DATAPROVIDERS_OPTION)) { if (dataLoader.isCsv()) { s_logger.warn( "Cannot specify data providers with CSV input files, since providers are part of the CSV file."); usage(options); return; } String[] dataProviders = splitByComma(line.getOptionValue(DATAPROVIDERS_OPTION)); dataLoader.setDataProviders(Arrays.asList(dataProviders)); } if (line.hasOption(START_OPTION)) { String startOption = line.getOptionValue(START_OPTION); try { LocalDate startDate = DateUtils.toLocalDate(startOption); dataLoader.setStartDate(startDate); } catch (Exception ex) { s_logger.warn("unable to parse start date {}", startOption); usage(options); return; } } if (line.hasOption(END_OPTION)) { String endOption = line.getOptionValue(END_OPTION); try { LocalDate endDate = DateUtils.toLocalDate(endOption); dataLoader.setEndDate(endDate); } catch (Exception ex) { s_logger.warn("unable to parse end date {}", endOption); usage(options); return; } } String[] fields = null; if (line.hasOption(FIELDS_OPTION)) { if (dataLoader.isCsv()) { s_logger.warn("Cannot specify fields with CSV input files, since fields are part of the CSV file."); usage(options); return; } fields = splitByComma(line.getOptionValue(FIELDS_OPTION)); dataLoader.setDataFields(Arrays.asList(fields)); } if (line.hasOption(UNIQUE_ID_OPTION)) { dataLoader.setBbgUniqueId(true); } //check we have right options and input files if (files != null && files.length > 0 && !dataLoader.isCsv() && (fields == null || fields.length == 0)) { s_logger.warn("DataFields must be specified"); usage(options); return; } }
From source file:com.facebook.LinkBench.LinkBenchDriver.java
/** * Process command line arguments and set static variables * exits program if invalid arguments provided * @param options//from w ww. j a v a 2 s.c om * @param args * @throws ParseException */ private static void processArgs(String[] args) throws ParseException { Options options = initializeOptions(); CommandLine cmd = null; try { CommandLineParser parser = new GnuParser(); cmd = parser.parse(options, args); } catch (ParseException ex) { // Use Apache CLI-provided messages System.err.println(ex.getMessage()); printUsage(options); System.exit(EXIT_BADARGS); } /* * Apache CLI validates arguments, so can now assume * all required options are present, etc */ if (cmd.getArgs().length > 0) { System.err.print("Invalid trailing arguments:"); for (String arg : cmd.getArgs()) { System.err.print(' '); System.err.print(arg); } System.err.println(); printUsage(options); System.exit(EXIT_BADARGS); } // Set static option variables doLoad = cmd.hasOption('l'); doRequest = cmd.hasOption('r'); logFile = cmd.getOptionValue('L'); // May be null configFile = cmd.getOptionValue('c'); if (configFile == null) { // Try to find in usual location String linkBenchHome = ConfigUtil.findLinkBenchHome(); if (linkBenchHome != null) { configFile = linkBenchHome + File.separator + "config" + File.separator + "LinkConfigMysql.properties"; } else { System.err.println("Config file not specified through command " + "line argument and " + ConfigUtil.linkbenchHomeEnvVar + " environment variable not set to valid directory"); printUsage(options); System.exit(EXIT_BADARGS); } } String csvStatsFileName = cmd.getOptionValue("csvstats"); // May be null if (csvStatsFileName != null) { try { csvStatsFile = new PrintStream(new FileOutputStream(csvStatsFileName)); } catch (FileNotFoundException e) { System.err.println("Could not open file " + csvStatsFileName + " for writing"); printUsage(options); System.exit(EXIT_BADARGS); } } String csvStreamFileName = cmd.getOptionValue("csvstream"); // May be null if (csvStreamFileName != null) { try { csvStreamFile = new PrintStream(new FileOutputStream(csvStreamFileName)); // File is written to by multiple threads, first write header SampledStats.writeCSVHeader(csvStreamFile); } catch (FileNotFoundException e) { System.err.println("Could not open file " + csvStreamFileName + " for writing"); printUsage(options); System.exit(EXIT_BADARGS); } } cmdLineProps = cmd.getOptionProperties("D"); if (!(doLoad || doRequest)) { System.err.println("Did not select benchmark mode"); printUsage(options); System.exit(EXIT_BADARGS); } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SetHypervolume.java
@Override public void run(CommandLine commandLine) throws Exception { for (String filename : commandLine.getArgs()) { NondominatedPopulation set = new NondominatedPopulation( PopulationIO.readObjectives(new File(filename))); if (commandLine.hasOption("epsilon")) { TypedProperties typedProperties = TypedProperties.withProperty("epsilon", commandLine.getOptionValue("epsilon")); set = new EpsilonBoxDominanceArchive(typedProperties.getDoubleArray("epsilon", null), set); }/*from w w w .j a v a2 s .c o m*/ System.out.print(filename); System.out.print(' '); System.out.println( new Hypervolume(new ProblemStub(set.get(0).getNumberOfObjectives()), set).evaluate(set)); } }