List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:alluxio.cli.fs.command.CreateLineageCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioLineage tl = AlluxioLineage.get(LineageContext.INSTANCE); // TODO(yupeng) more validation List<AlluxioURI> inputFiles = new ArrayList<>(); if (!args[0].equals("noInput")) { for (String path : args[0].split(",")) { inputFiles.add(new AlluxioURI(path)); }//from w ww . ja va2 s . com } List<AlluxioURI> outputFiles = new ArrayList<>(); for (String path : args[1].split(",")) { outputFiles.add(new AlluxioURI(path)); } String cmd = ""; for (int i = 2; i < args.length; i++) { cmd += args[i] + " "; } String outputPath = Configuration.get(PropertyKey.MASTER_LINEAGE_RECOMPUTE_LOG_PATH); if (outputPath == null) { throw new IOException("recompute output log is not configured"); } CommandLineJob job = new CommandLineJob(cmd, new JobConf(outputPath)); long lineageId = tl.createLineage(inputFiles, outputFiles, job); System.out.println("Lineage " + lineageId + " has been created."); return 0; }
From source file:alluxio.shell.command.CheckConsistencyCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI root = new AlluxioURI(args[0]); checkConsistency(root, cl.hasOption("r")); return 0;//from w ww .ja v a2 s.com }
From source file:ch.ethz.topobench.graph.traffic.generators.AllToAllTrafficGenerator.java
@Override public SelectorResult<Traffic> generate(Graph graph, String[] args) { // Parse the options CommandLine cmd = CmdAssistant.parseOptions(new Options(), args, false); // Return traffic return new SelectorResult<>(new AllToAllTraffic(graph), cmd.getArgs()); }
From source file:ch.ethz.topobench.graph.traffic.generators.AllToOneTrafficGenerator.java
@Override public SelectorResult<Traffic> generate(Graph graph, String[] args) { // Parse the options CommandLine cmd = CmdAssistant.parseOptions(new Options(), args, false); // Return traffic return new SelectorResult<>(new AllToOneTraffic(graph), cmd.getArgs()); }
From source file:alluxio.cli.fs.command.HeadCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); mNumOfBytes = Constants.KB;// w w w. j av a 2 s . co m if (cl.hasOption('c')) { mNumOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c')); Preconditions.checkArgument(mNumOfBytes > 0, "specified bytes must be > 0"); } AlluxioURI path = new AlluxioURI(args[0]); runWildCardCmd(path, cl); return 0; }
From source file:fr.liglab.consgap.Main.java
private static void standalone(CommandLine cmd) throws IOException { if (cmd.hasOption("sep")) { Main.separator = cmd.getOptionValue("sep"); }/* w ww .j av a 2 s .com*/ int nbThreads = Runtime.getRuntime().availableProcessors(); if (cmd.hasOption('t')) { nbThreads = Math.max(1, Integer.parseInt(cmd.getOptionValue('t'))); } ResultsCollector collector; MiningExecutor executor; if (cmd.hasOption('w')) { collector = new OrderedResultsCollector(); executor = new BreadthFirstExecutor(nbThreads); } else { executor = new DepthFirstExecutor(nbThreads); if (cmd.hasOption('f')) { collector = new BatchFilteringResultsCollector(Integer.parseInt(cmd.getOptionValue('f'))); } else { collector = new PostFilteringResultsCollector(); } } Dataset dataset; if (cmd.hasOption('l')) { if (cmd.hasOption('s')) { dataset = new TransBasedListDataset(collector, cmd.getArgs()[0], cmd.getArgs()[1], Integer.parseInt(cmd.getArgs()[2]), Integer.parseInt(cmd.getArgs()[3]), Integer.parseInt(cmd.getArgs()[4])); } else { dataset = new TransBasedBitSetDataset(collector, cmd.getArgs()[0], cmd.getArgs()[1], Integer.parseInt(cmd.getArgs()[2]), Integer.parseInt(cmd.getArgs()[3]), Integer.parseInt(cmd.getArgs()[4])); } } else { if (cmd.hasOption('s')) { dataset = new ListDataset(collector, cmd.getArgs()[0], cmd.getArgs()[1], Integer.parseInt(cmd.getArgs()[2]), Integer.parseInt(cmd.getArgs()[3]), Integer.parseInt(cmd.getArgs()[4])); } else { dataset = new BitSetDataset(collector, cmd.getArgs()[0], cmd.getArgs()[1], Integer.parseInt(cmd.getArgs()[2]), Integer.parseInt(cmd.getArgs()[3]), Integer.parseInt(cmd.getArgs()[4])); } } long startTime = System.currentTimeMillis(); executor.mine(dataset); long removeRedundantStart = System.currentTimeMillis(); List<String[]> minimalEmerging = dataset.getResultsCollector().getNonRedundant(); if (!cmd.hasOption('b')) { for (String[] seq : minimalEmerging) { for (int i = 0; i < seq.length; i++) { System.out.print(seq[i] + "\t"); } System.out.println(); } } long endTime = System.currentTimeMillis(); System.err.println("total minimal emerging sequences = " + minimalEmerging.size() + "\ntotal sequences collected = " + dataset.getResultsCollector().getNbCollected()); System.err.println("execution time " + (endTime - startTime) + " ms including " + (endTime - removeRedundantStart) + " ms removing redundant results, performed " + MiningStep.loopCounts.get() + " iterations"); }
From source file:com.netscape.cmstools.ca.CACertShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from ww w . j a v a 2 s .c o m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("Missing Serial Number."); } boolean showPrettyPrint = cmd.hasOption("pretty"); boolean showEncoded = cmd.hasOption("encoded"); CertId certID = new CertId(cmdArgs[0]); String file = cmd.getOptionValue("output"); CACertClient certClient = certCLI.getCertClient(); CertData certData = certClient.getCert(certID); String encoded = certData.getEncoded(); if (encoded != null && file != null) { // store cert to file try (PrintWriter out = new PrintWriter(new FileWriter(file))) { out.print(encoded); } } MainCLI.printMessage("Certificate \"" + certID.toHexString() + "\""); CACertCLI.printCertData(certData, showPrettyPrint, showEncoded); }
From source file:es.csic.iiia.planes.generator.Cli.java
/** * Parse the provided list of arguments according to the program's options. * * @param in_args list of input arguments. * @return a configuration object set according to the input options. */// w ww . j a v a 2 s .c o m private static Configuration parseOptions(String[] in_args) { CommandLineParser parser = new PosixParser(); CommandLine line = null; Properties settings = loadDefaultSettings(); try { line = parser.parse(options, in_args); } catch (ParseException ex) { Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex); showHelp(); } if (line.hasOption('h')) { showHelp(); } if (line.hasOption('d')) { dumpSettings(); } if (line.hasOption('s')) { String fname = line.getOptionValue('s'); try { settings.load(new FileReader(fname)); } catch (IOException ex) { throw new IllegalArgumentException("Unable to load the settings file \"" + fname + "\""); } } // Apply overrides settings.setProperty("quiet", String.valueOf(line.hasOption('q'))); Properties overrides = line.getOptionProperties("o"); settings.putAll(overrides); String[] args = line.getArgs(); if (args.length < 1) { showHelp(); } settings.setProperty("problem", args[0]); Configuration c = new Configuration(settings); if (line.hasOption('t')) { System.exit(0); } return c; }
From source file:com.netscape.cmstools.user.UserCertShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from w w w. j av a 2s .co m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 2) { throw new Exception("Incorrect number of arguments specified."); } boolean showPrettyPrint = cmd.hasOption("pretty"); boolean showEncoded = cmd.hasOption("encoded"); String userID = cmdArgs[0]; String certID = cmdArgs[1]; String file = cmd.getOptionValue("output"); UserClient userClient = userCertCLI.getUserClient(); UserCertData userCertData = userClient.getUserCert(userID, URLEncoder.encode(certID, "UTF-8")); String encoded = userCertData.getEncoded(); if (encoded != null && file != null) { // store cert to file PrintWriter out = new PrintWriter(new FileWriter(file)); out.print(encoded); out.close(); } MainCLI.printMessage("Certificate \"" + userCertData.getID() + "\""); UserCertCLI.printCert(userCertData, showPrettyPrint, showEncoded); }
From source file:com.galenframework.actions.GalenActionCheckArguments.java
public static GalenActionCheckArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("i", "include", true, "Tags for sections that should be included in test run"); options.addOption("e", "exclude", true, "Tags for sections that should be excluded from test run"); options.addOption("h", "htmlreport", true, "Path for html output report"); options.addOption("j", "jsonreport", true, "Path for json report"); options.addOption("g", "testngreport", true, "Path for testng xml report"); options.addOption("u", "url", true, "Initial test url"); options.addOption("s", "size", true, "Browser window size"); options.addOption("J", "javascript", true, "JavaScript code that should be executed before checking layout"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try {/*from w w w . j a v a2 s . com*/ 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); } GalenActionCheckArguments arguments = new GalenActionCheckArguments(); arguments.setTestngReport(cmd.getOptionValue("g")); arguments.setHtmlReport(cmd.getOptionValue("h")); arguments.setJsonReport(cmd.getOptionValue("j")); arguments.setUrl(cmd.getOptionValue("u")); arguments.setScreenSize(convertScreenSize(cmd.getOptionValue("s"))); arguments.setJavascript(cmd.getOptionValue("J")); arguments.setIncludedTags(convertTags(cmd.getOptionValue("i"))); arguments.setExcludedTags(convertTags(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); if (paths.isEmpty()) { throw new IllegalArgumentException("Missing spec files"); } return arguments; }