List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:com.nec.congenio.ConfigCli.java
private ValueExecBuilder builder(CommandLine cline) { String[] cmdArgs = cline.getArgs(); ConfigDescription cdl = createDescription(cline, new File(cmdArgs[0])); ValueExecBuilder builder = new ValueExecBuilder(cdl).filterIndex(cline.getOptionValue(LOPT_INDEX)) .path(cline.getOptionValue(LOPT_PATH)); return builder; }
From source file:com.nec.congenio.ConfigCli.java
private void showExtendOnly(CommandLine cline) { String[] args = cline.getArgs(); if (args.length != 1) { doHelp();//w w w . j av a 2 s .c om } else { ConfigDescription cdl = createDescription(cline, new File(args[0])); OutputStreamWriter writer = new OutputStreamWriter(System.out); cdl.write(writer, true); } }
From source file:de.clusteval.data.dataset.generator.CassiniDataSetGenerator.java
@Override protected void handleOptions(CommandLine cmd) throws ParseException { if (cmd.getArgList().size() > 0) throw new ParseException("Unknown parameters: " + Arrays.toString(cmd.getArgs())); if (cmd.hasOption("n")) this.numberOfPoints = Integer.parseInt(cmd.getOptionValue("n")); else/* w w w .j av a 2 s .co m*/ this.numberOfPoints = 100; }
From source file:edu.wpi.checksims.ChecksimsCommandLine.java
/** * Parse CLI arguments into a ChecksimsConfig. * * Also configures logger, and sets parallelism level in ParallelAlgorithm * * TODO add unit tests//from w ww .j a va 2 s .c o m * * @param args CLI arguments to parse * @return Config created from CLI arguments * @throws ParseException Thrown on error parsing CLI arguments * @throws IOException Thrown on error building a submission from files */ static ChecksimsConfig parseCLI(String[] args) throws ParseException, ChecksimsException, IOException { checkNotNull(args); CommandLine cli = parseOpts(args); // Print CLI Help if (cli.hasOption("h")) { printHelp(); } // Print version if (cli.hasOption("version")) { System.err.println("Checksims version " + ChecksimsRunner.getChecksimsVersion()); System.exit(0); } // Parse verbose setting if (cli.hasOption("vv")) { logs = startLogger(2); } else if (cli.hasOption("v")) { logs = startLogger(1); } else { logs = startLogger(0); } // Parse recursive flag boolean recursive = false; if (cli.hasOption("r")) { recursive = true; logs.trace("Recursively traversing subdirectories of student directories"); } // Get unconsumed arguments String[] unusedArgs = cli.getArgs(); if (unusedArgs.length < 2) { throw new ChecksimsException( "Expecting at least two arguments: File match glob, and folder(s) to check"); } // First non-flag argument is the glob matcher // All the rest are directories containing student submissions String glob = unusedArgs[0]; // First, parse basic flags ChecksimsConfig config = parseBaseFlags(cli); // Set up a tokenizer to use Tokenizer tokenizer = Tokenizer.getTokenizer(config.getTokenization()); // Next, parse common code settings CommonCodeHandler handler = parseCommonCodeSetting(cli, glob, tokenizer, recursive); config = config.setCommonCodeHandler(handler); // Next, build submissions Set<Submission> submissions = getSubmissions(cli, glob, tokenizer, recursive); config = config.setSubmissions(submissions); logs.trace("CLI parsing complete!"); return config; }
From source file:com.netscape.cmstools.ca.CACertRevokeCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/*from w ww .java 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."); } CertId certID = new CertId(cmdArgs[0]); String string = cmd.getOptionValue("reason", RevocationReason.UNSPECIFIED.toString()); RevocationReason reason = RevocationReason.valueOf(string); if (reason == null) { throw new Exception("Invalid revocation reason: " + string); } CACertClient certClient = certCLI.getCertClient(); CertData certData = certClient.reviewCert(certID); if (!cmd.hasOption("force")) { if (reason == RevocationReason.CERTIFICATE_HOLD) { System.out.println("Placing certificate on-hold:"); } else if (reason == RevocationReason.REMOVE_FROM_CRL) { System.out.println("Placing certificate off-hold:"); } else { System.out.println("Revoking certificate:"); } CACertCLI.printCertData(certData, false, false); if (verbose) System.out.println(" Nonce: " + certData.getNonce()); System.out.print("Are you sure (Y/N)? "); System.out.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine(); if (!line.equalsIgnoreCase("Y")) { return; } } CertRevokeRequest request = new CertRevokeRequest(); request.setReason(reason); request.setComments(cmd.getOptionValue("comments")); request.setNonce(certData.getNonce()); CertRequestInfo certRequestInfo; if (cmd.hasOption("ca")) { certRequestInfo = certClient.revokeCACert(certID, request); } else { certRequestInfo = certClient.revokeCert(certID, request); } if (verbose) { CACertCLI.printCertRequestInfo(certRequestInfo); } if (certRequestInfo.getRequestStatus() == RequestStatus.COMPLETE) { if (certRequestInfo.getOperationResult().equals(CertRequestInfo.RES_ERROR)) { String error = certRequestInfo.getErrorMessage(); if (error != null) { System.out.println(error); } MainCLI.printMessage("Could not revoke certificate \"" + certID.toHexString() + "\""); } else { if (reason == RevocationReason.CERTIFICATE_HOLD) { MainCLI.printMessage("Placed certificate \"" + certID.toHexString() + "\" on-hold"); } else if (reason == RevocationReason.REMOVE_FROM_CRL) { MainCLI.printMessage("Placed certificate \"" + certID.toHexString() + "\" off-hold"); } else { MainCLI.printMessage("Revoked certificate \"" + certID.toHexString() + "\""); } certData = certClient.getCert(certID); CACertCLI.printCertData(certData, false, false); } } else { MainCLI.printMessage( "Request \"" + certRequestInfo.getRequestId() + "\": " + certRequestInfo.getRequestStatus()); } }
From source file:alluxio.shell.command.TestCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { if (cl.getOptions().length > 1) { return 1; }// w w w.ja v a2s.c o m String[] args = cl.getArgs(); AlluxioURI path = new AlluxioURI(args[0]); try { URIStatus status = mFileSystem.getStatus(path); boolean testResult = false; if (cl.hasOption("d")) { if (isDir(status)) { testResult = true; } } else if (cl.hasOption("f")) { if (isFile(status)) { testResult = true; } } else if (cl.hasOption("e")) { testResult = true; } else if (cl.hasOption("s")) { if (isNonEmptyDir(status)) { testResult = true; } } else if (cl.hasOption("z")) { if (isZeroLengthFile(status)) { testResult = true; } } return testResult ? 0 : 1; } catch (AlluxioException | IOException e) { return 1; } }
From source file:com.brewtab.ircbot.applets.StockApplet.java
private List<String> getResponse(String[] args) { CommandLine cmdline; try {// w w w . j ava 2s . c o m cmdline = parser.parse(options, args); } catch (ParseException e) { return Arrays.asList("Error: " + e.getMessage()); } List<String> symbols = Arrays.asList(cmdline.getArgs()); if (symbols.size() == 0) { return Arrays.asList("Error: at least one stock symbol must be given"); } List<QuoteField> fields = Arrays.asList(QuoteField.SYMBOL, QuoteField.NAME, QuoteField.LAST_TRADE_PRICE_ONLY, QuoteField.CHANGE, QuoteField.PERCENT_CHANGE, QuoteField.MARKET_CAP, QuoteField.PE_RATIO, QuoteField.FIFTY_TWO_WEEK_HIGH, QuoteField.FIFTY_TWO_WEEK_LOW); List<Quote> quotes = Quote.forSymbols(symbols, fields); List<String> lines = new ArrayList<String>(); if (cmdline.hasOption('v')) { for (Quote quote : quotes) { lines.add(String.format("%s: %s", quote.get(QuoteField.SYMBOL), quote.get(QuoteField.NAME))); lines.add(String.format(" Current: %s (%s, %s)", quote.get(QuoteField.LAST_TRADE_PRICE_ONLY), quote.get(QuoteField.CHANGE), quote.get(QuoteField.PERCENT_CHANGE))); for (QuoteField field : fields.subList(5, fields.size())) { lines.add(String.format(" %s %s", field.getDescription() + ":", quote.get(field))); } } } else { for (Quote quote : quotes) { lines.add(String.format("%s: %s (%s, %s)", quote.get(QuoteField.SYMBOL), quote.get(QuoteField.LAST_TRADE_PRICE_ONLY), quote.get(QuoteField.CHANGE), quote.get(QuoteField.PERCENT_CHANGE))); } } return lines; }
From source file:alluxio.cli.fs.command.TestCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { if (cl.getOptions().length > 1) { return -1; }/*from w ww . j a v a 2 s .c o m*/ String[] args = cl.getArgs(); AlluxioURI path = new AlluxioURI(args[0]); try { URIStatus status = mFileSystem.getStatus(path); boolean testResult = false; if (cl.hasOption("d")) { if (isDir(status)) { testResult = true; } } else if (cl.hasOption("f")) { if (isFile(status)) { testResult = true; } } else if (cl.hasOption("e")) { testResult = true; } else if (cl.hasOption("s")) { if (isNonEmptyDir(status)) { testResult = true; } } else if (cl.hasOption("z")) { if (isZeroLengthFile(status)) { testResult = true; } } else { return -1; } return testResult ? 0 : 1; } catch (AlluxioException | IOException e) { return 1; } }
From source file:ch.ethz.topobench.graph.traffic.generators.StrideTrafficGenerator.java
@Override public SelectorResult<Traffic> generate(Graph graph, String[] args) { // Parse the options Options options = new Options(); CmdAssistant.addOption(options, "str", "stride", true, "server stride (must not be divisible by number of servers)"); CommandLine cmd = CmdAssistant.parseOptions(options, args, false); // Retrieve parameters int stride = ArgumentValidator.retrieveInteger("stride", cmd.getOptionValue("stride")); // Return traffic return new SelectorResult<>(new StrideTraffic(graph, stride), cmd.getArgs()); }
From source file:alluxio.cli.AbstractCommand.java
@Override public CommandLine parseAndValidateArgs(String... args) throws InvalidArgumentException { Options opts = getOptions();/*from w ww . j av a2 s . co m*/ CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(opts, args); } catch (ParseException e) { throw new InvalidArgumentException(String.format("Failed to parse args for %s", getCommandName()), e); } validateArgs(cmd.getArgs()); return cmd; }