List of usage examples for org.apache.commons.cli CommandLine getOptionValues
public String[] getOptionValues(char opt)
From source file:net.librec.tool.driver.DataDriver.java
/** * Execute the command with the given arguments. * * @param args command specific arguments. * @return exit code./* w w w .ja v a2 s.c o m*/ * @throws Exception if error occurs */ public int run(String[] args) throws Exception { // init options Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); // parse options CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args, false); // init configuration Configuration conf = new Configuration(); if (cmd.hasOption("conf")) { String confFilePath = cmd.getOptionValue("conf"); Properties prop = new Properties(); prop.load(new FileInputStream(confFilePath)); for (String name : prop.stringPropertyNames()) { conf.set(name, prop.getProperty(name)); } } if (cmd.hasOption("jobconf")) { String[] optionValues = cmd.getOptionValues("jobconf"); for (String optionValue : optionValues) { String[] keyValuePair = optionValue.split("="); conf.set(keyValuePair[0], keyValuePair[1]); } } if (cmd.hasOption("D")) { String[] optionValues = cmd.getOptionValues("D"); for (String optionValue : optionValues) { String[] keyValuePair = optionValue.split("="); conf.set(keyValuePair[0], keyValuePair[1]); } } TextDataModel dataModel = new TextDataModel(conf); dataModel.buildDataModel(); System.out.println("well done!!!"); return 0; }
From source file:net.librec.tool.driver.RecDriver.java
/** * Execute the command with the given arguments. * * @param args command specific arguments. * @return exit code./*from w w w . java 2s .c o m*/ * @throws Exception if error occurs */ public int run(String[] args) throws Exception { // init options Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("exec", false, "run job"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); // parse options CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args, false); // init configuration Configuration conf = new Configuration(); if (cmd.hasOption("conf")) { String confFilePath = cmd.getOptionValue("conf"); Properties prop = new Properties(); prop.load(new FileInputStream(confFilePath)); for (String name : prop.stringPropertyNames()) { conf.set(name, prop.getProperty(name)); } } if (cmd.hasOption("jobconf")) { String[] optionValues = cmd.getOptionValues("jobconf"); for (String optionValue : optionValues) { String[] keyValuePair = optionValue.split("="); conf.set(keyValuePair[0], keyValuePair[1]); } } if (cmd.hasOption("D")) { String[] optionValues = cmd.getOptionValues("D"); for (String optionValue : optionValues) { String[] keyValuePair = optionValue.split("="); conf.set(keyValuePair[0], keyValuePair[1]); } } //run job RecommenderJob job = new RecommenderJob(conf); job.runJob(); System.out.print("Finished"); return 0; }
From source file:com.facebook.presto.accumulo.tools.RewriteMetricsTask.java
@Override public int run(AccumuloConfig config, CommandLine cmd) throws Exception { this.setConfig(config); if (cmd.hasOption(AUTHORIZATIONS_OPT)) { this.setAuthorizations(new Authorizations(cmd.getOptionValues(AUTHORIZATIONS_OPT))); }/* w ww .j a v a 2 s. c o m*/ this.setSchema(cmd.getOptionValue(SCHEMA_OPT)); this.setTableName(cmd.getOptionValue(TABLE_OPT)); this.setDryRun(!cmd.hasOption(FORCE_OPT)); return this.exec(); }
From source file:net.imagini.cassandra.DumpSSTables.SSTableExport.java
private static void readSSTables(File ssTableFileName, CommandLine cmd) throws IOException { if (ssTableFileName.exists()) { if (ssTableFileName.isDirectory()) { Collection<File> files = org.apache.commons.io.FileUtils.listFiles(ssTableFileName, new RegexFileFilter("^.*Data\\.db"), DirectoryFileFilter.DIRECTORY); for (File file : files) { readSSTables(file, cmd); }//from w w w .j a va 2 s . c o m } else if (ssTableFileName.isFile()) { Descriptor descriptor = Descriptor.fromFilename(ssTableFileName.getAbsolutePath()); if (Schema.instance.getCFMetaData(descriptor) == null) { System.err.println(String.format( "The provided column family is not part of this cassandra database: keysapce = %s, column family = %s", descriptor.ksname, descriptor.cfname)); System.exit(1); } if (cmd.hasOption(ENUMERATEKEYS_OPTION)) { enumeratekeys(descriptor, System.out); } else { if ((cmd.getOptionValues(KEY_OPTION) != null) && (cmd.getOptionValues(KEY_OPTION).length > 0)) export(descriptor, System.out, Arrays.asList(cmd.getOptionValues(KEY_OPTION)), cmd.getOptionValues(EXCLUDEKEY_OPTION)); else export(descriptor, cmd.getOptionValues(EXCLUDEKEY_OPTION)); } } } }
From source file:com.facebook.presto.accumulo.tools.RewriteIndex.java
@Override public int run(AccumuloConfig config, CommandLine cmd) throws Exception { this.setConfig(config); if (cmd.hasOption(AUTHORIZATIONS_OPT)) { this.setAuthorizations(new Authorizations(cmd.getOptionValues(AUTHORIZATIONS_OPT))); }/*from w w w . ja va 2 s . co m*/ this.setSchema(cmd.getOptionValue(SCHEMA_OPT)); this.setTableName(cmd.getOptionValue(TABLE_OPT)); this.setDryRun(!cmd.hasOption(FORCE_OPT)); this.setAddOnly(cmd.hasOption(ADD_ONLY_OPT)); return this.exec(); }
From source file:net.sf.clirr.cli.Clirr.java
private void run(String[] args) { Options options = defineOptions();/*from w w w. j av a 2s . c om*/ CommandLine cmdline = parseCommandLine(args, options); String oldPath = cmdline.getOptionValue('o'); String newPath = cmdline.getOptionValue('n'); String oldClassPath = cmdline.getOptionValue("ocp"); String newClassPath = cmdline.getOptionValue("ncp"); String style = cmdline.getOptionValue('s', "text"); String outputFileName = cmdline.getOptionValue('f'); String[] includePkgs = cmdline.getOptionValues('i'); boolean showAll = cmdline.hasOption('a'); boolean showPkg = cmdline.hasOption('p'); if ((oldPath == null) || (newPath == null)) { printUsage(options, System.err); System.exit(-1); } Checker checker = new Checker(); if (showAll) { checker.getScopeSelector().setScope(Scope.PRIVATE); } else if (showPkg) { checker.getScopeSelector().setScope(Scope.PACKAGE); } ClassSelector classSelector; if ((includePkgs != null) && (includePkgs.length > 0)) { classSelector = new ClassSelector(ClassSelector.MODE_IF); for (int i = 0; i < includePkgs.length; ++i) { classSelector.addPackageTree(includePkgs[i]); } } else { // a selector that selects everything classSelector = new ClassSelector(ClassSelector.MODE_UNLESS); } DiffListener diffListener = null; if (style.equals("text")) { try { diffListener = new PlainDiffListener(outputFileName); } catch (IOException ex) { System.err.println("Invalid output file name."); } } else if (style.equals("xml")) { try { diffListener = new XmlDiffListener(outputFileName); } catch (IOException ex) { System.err.println("Invalid output file name."); } } else { System.err.println("Invalid style option. Must be one of 'text', 'xml'."); printUsage(options, System.err); System.exit(-1); } File[] origClassPathEntries = pathToFileArray(oldPath); File[] newClassPathEntries = pathToFileArray(newPath); checker.addDiffListener(diffListener); try { ClassLoader loader1 = new URLClassLoader(convertFilesToURLs(pathToFileArray(oldClassPath))); ClassLoader loader2 = new URLClassLoader(convertFilesToURLs(pathToFileArray(newClassPath))); DefaultTypeArrayBuilderFactory tabFactory = new DefaultTypeArrayBuilderFactory(); TypeArrayBuilder tab1 = tabFactory.build(); TypeArrayBuilder tab2 = tabFactory.build(); final JavaType[] origClasses = tab1.createClassSet(origClassPathEntries, loader1, classSelector); final JavaType[] newClasses = tab2.createClassSet(newClassPathEntries, loader2, classSelector); checker.reportDiffs(origClasses, newClasses); System.exit(0); } catch (CheckerException ex) { System.err.println("Unable to complete checks: " + ex.getMessage()); System.exit(1); } catch (MalformedURLException ex) { System.err.println("Unable to create classloader for 3rd party classes: " + ex.getMessage()); System.err.println("old classpath: " + oldClassPath); System.err.println("new classpath: " + newClassPath); System.exit(1); } catch (RuntimeException ex) { System.err.println("Unable to complete checks: " + ex.toString()); Throwable cause = ex.getCause(); if (cause != null) { System.err.println(" caused by : " + cause.toString()); } System.exit(2); } }
From source file:com.monami_ya.mwe2.launch.runtime.AWorkflowLauncher.java
@Override public void run(String[] args) { Options options = getOptions();//from w ww. ja v a 2s . c o m final CommandLineParser parser = new PosixParser(); CommandLine line = null; try { line = parser.parse(options, args); if (line.getArgs().length == 0) throw new ParseException("No module name specified."); if (line.getArgs().length > 1) throw new ParseException("Only one module name expected. But " + line.getArgs().length + " were passed (" + line.getArgList() + ")"); String moduleName = line.getArgs()[0]; Map<String, String> params = new HashMap<String, String>(); String[] optionValues = line.getOptionValues(PARAM); if (optionValues != null) { for (String string : optionValues) { int index = string.indexOf('='); if (index == -1) { throw new ParseException( "Incorrect parameter syntax '" + string + "'. It should be 'name=value'"); } String name = string.substring(0, index); String value = string.substring(index + 1); if (params.put(name, value) != null) { throw new ParseException("Duplicate parameter '" + name + "'."); } } } // check OperationCanceledException is accessible OperationCanceledException.class.getName(); Injector injector = new AWorkflowStandaloneSetup().createInjectorAndDoEMFRegistration(); Mwe2Runner mweRunner = injector.getInstance(Mwe2Runner.class); if (moduleName.contains("/")) { mweRunner.run(URI.createURI(moduleName), params); } else { mweRunner.run(moduleName, params); } } catch (NoClassDefFoundError e) { if ("org/eclipse/core/runtime/OperationCanceledException".equals(e.getMessage())) { System.err.println("Could not load class: org.eclipse.core.runtime.OperationCanceledException"); System.err.println("Add org.eclipse.equinox.common to the class path."); } else { throw e; } } catch (final ParseException exp) { final HelpFormatter formatter = new HelpFormatter(); System.err.println("Parsing arguments failed. Reason: " + exp.getMessage()); formatter.printHelp("java " + AWorkflowLauncher.class.getName() + " some.mwe2.Module [options]\n", options); return; } }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseScaleOption(CommandLine line) throws ParseException { if (line.hasOption(SCALE)) { if (line.getOptionValues(SCALE).length != 2) { throw new ParseException("2 arguments needed for scaling."); }//from w ww . j a v a 2 s . c o m String value = line.getOptionValues(SCALE)[0]; scaleX = Optional.of(ToolBox.getDouble(value)); if (scaleX.get() < MIN_FREE_SCALE_FACTOR || scaleX.get() > MAX_FREE_SCALE_FACTOR) { throw new ParseException("Invalid x scaling factor: " + value); } value = line.getOptionValues(SCALE)[1]; scaleY = Optional.of(ToolBox.getDouble(value)); if (scaleY.get() < MIN_FREE_SCALE_FACTOR || scaleY.get() > MAX_FREE_SCALE_FACTOR) { throw new ParseException("Invalid y scaling factor: " + value); } } }
From source file:com.eviware.soapui.tools.SoapUIToolRunner.java
@Override protected boolean processCommandLine(CommandLine cmd) { setTool(cmd.getOptionValue("t")); if (cmd.hasOption("i")) setInterface(cmd.getOptionValue("i")); if (cmd.hasOption("s")) setSettingsFile(getCommandLineOptionSubstSpace(cmd, "s")); if (cmd.hasOption("x")) { setProjectPassword(cmd.getOptionValue("x")); }//from w w w . java 2 s .c o m if (cmd.hasOption("v")) { setSoapUISettingsPassword(cmd.getOptionValue("v")); } if (cmd.hasOption("D")) { setSystemProperties(cmd.getOptionValues("D")); } if (cmd.hasOption("G")) { setGlobalProperties(cmd.getOptionValues("G")); } if (cmd.hasOption("f")) setOutputFolder(cmd.getOptionValue("f")); return true; }
From source file:gov.llnl.lc.smt.command.privileged.SmtPrivileged.java
private boolean saveCommandArgs(String cName, Map<String, String> config, CommandLine line) { if (line.hasOption(cName)) { config.put(SmtProperty.SMT_SUBCOMMAND.getName(), cName); config.put(ARG_ID, ""); // there may be command arguments, get them all, and concatenate them String[] args = line.getOptionValues(cName); if ((args == null || args.length < 0)) { // log an error, and exit System.err.println("argument error"); return false; }/*ww w. j av a 2 s . c o m*/ // save all the arguments in a single parameter StringBuffer cmdArgs = new StringBuffer(); for (String arg : args) { cmdArgs.append(arg + " "); } config.put(ARG_ID, cmdArgs.toString().trim()); config.put(cName, cmdArgs.toString().trim()); return true; } return false; }