List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:com.galenframework.parser.GalenPageActionReader.java
private static GalenPageAction dumpPageActionFrom(String[] args, String originalText) { Options options = new Options(); options.addOption("n", "name", true, "Page name"); options.addOption("e", "export", true, "Export dir"); options.addOption("w", "max-width", true, "Maximal width of elements in croppped screenshots"); options.addOption("h", "max-height", true, "Maximal height of elements in cropped screenshots"); options.addOption("i", "only-images", false, "Flag for exporting only images without html and json files"); org.apache.commons.cli.CommandLineParser parser = new PosixParser(); try {/*from ww w . jav a 2 s .c o m*/ CommandLine cmd = parser.parse(options, args); String[] leftoverArgs = cmd.getArgs(); if (leftoverArgs == null || leftoverArgs.length < 2) { throw new SyntaxException(Line.UNKNOWN_LINE, "There are no page specs: " + originalText); } Integer maxWidth = null; Integer maxHeight = null; String maxWidthText = cmd.getOptionValue("w"); String maxHeightText = cmd.getOptionValue("h"); if (maxWidthText != null && !maxWidthText.isEmpty()) { maxWidth = Integer.parseInt(maxWidthText); } if (maxHeightText != null && !maxHeightText.isEmpty()) { maxHeight = Integer.parseInt(maxHeightText); } boolean onlyImages = cmd.hasOption("i"); return new GalenPageActionDumpPage().withSpecPath(leftoverArgs[1]).withPageName(cmd.getOptionValue("n")) .withPageDumpPath(cmd.getOptionValue("e")).withMaxWidth(maxWidth).withMaxHeight(maxHeight) .withOnlyImages(onlyImages); } catch (Exception e) { throw new SyntaxException(Line.UNKNOWN_LINE, "Couldn't parse: " + originalText, e); } }
From source file:io.janusproject.Boot.java
private static void parseCommandForInfoOptions(CommandLine cmd) { if (cmd.hasOption('h') || cmd.getArgs().length == 0) { showHelp();/*from ww w.j av a 2 s . c o m*/ } if (cmd.hasOption('s')) { showDefaults(); } }
From source file:it.scompo.audioorganizer.setup.PropertiesConfigurator.java
public static void createApplicationProperties(String... args) { CommandLine line = null; String[] remainingArguments = null; try {//from w ww . j av a 2 s .c o m line = parser.parse(optionsDefinitions.getOptions(), args, true); } catch (ParseException e) { exitApplication(STATUS_ERROR); } remainingArguments = line.getArgs(); if (line.hasOption("help")) { printHelp(); exitApplication(STATUS_OK); } if (noMoreArgs(remainingArguments)) { printHelp(); exitApplication(STATUS_ERROR); } if (line.hasOption("recursive")) { applicationProperties.setRecursive(true); } applicationProperties.setDirectoryPath(remainingArguments[0]); }
From source file:de.huberlin.wbi.cuneiform.cmdline.main.Main.java
public static void config(CommandLine cmd) { String[] fileVector;//from w ww .jav a 2 s. co m Path f; String s; int i, n; fileVector = cmd.getArgs(); n = fileVector.length; inputFileVector = new Path[n]; for (i = 0; i < n; i++) { s = fileVector[i]; f = Paths.get(s); inputFileVector[i] = f; } if (cmd.hasOption('p')) platform = cmd.getOptionValue('p'); else platform = PLATFORM_LOCAL; if (cmd.hasOption('f')) format = cmd.getOptionValue('f'); else format = FORMAT_CF; }
From source file:edu.hku.sdb.driver.SdbDriver.java
private static CommandLine parseAndValidateInput(String[] args) { // Make sure we have some if (args == null || args.length == 0) { //printUsage(System.out); //System.exit(0); }//from w w w . j a v a2 s.co m // Parse the arguments Options opts = buildOptions(); CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(opts, args, true); } catch (ParseException e) { failAndExit("Unable to parse the input arguments:\n" + e.getMessage()); } // Ensure we don't have any extra input arguments if (line.getArgs() != null && line.getArgs().length > 0) { System.err.println("Unsupported input arguments:"); for (String arg : line.getArgs()) { System.err.println(arg); } failAndExit(""); } // If the user asked for help, nothing else to do if (line.hasOption(HELP)) { return line; } if (!line.hasOption(START)) { printUsage(System.out); failAndExit(""); } if (!line.hasOption(CONF)) { printUsage(System.out); failAndExit(""); } return line; }
From source file:edu.kit.checkstyle.Main.java
/** * Determines the files to process./* w w w . java 2 s . co m*/ * * @param aLine the command line options specifying what files to process * @return list of files to process */ private static List<File> getFilesToProcess(CommandLine aLine) { final List<File> files = Lists.newLinkedList(); if (aLine.hasOption("r")) { final String[] values = aLine.getOptionValues("r"); for (String element : values) { traverse(new File(element), files); } } final String[] remainingArgs = aLine.getArgs(); for (String element : remainingArgs) { files.add(new File(element)); } return files; }
From source file:alluxio.cli.GetConf.java
/** * Implements get configuration.// w w w .ja v a2s.c om * * @param args list of arguments * @return 0 on success, 1 on failures */ public static int getConf(String... args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(OPTIONS, args, true /* stopAtNonOption */); } catch (ParseException e) { printHelp("Unable to parse input args: " + e.getMessage()); return 1; } Preconditions.checkNotNull(cmd, "Unable to parse input args"); args = cmd.getArgs(); switch (args.length) { case 0: for (Entry<String, String> entry : Configuration.toMap().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); System.out.println(String.format("%s=%s", key, value)); } break; case 1: if (!PropertyKey.isValid(args[0])) { printHelp(String.format("%s is not a valid configuration key", args[0])); return 1; } PropertyKey key = PropertyKey.fromString(args[0]); if (!Configuration.containsKey(key)) { System.out.println(""); } else { if (cmd.hasOption(UNIT_OPTION_NAME)) { String arg = cmd.getOptionValue(UNIT_OPTION_NAME).toUpperCase(); try { ByteUnit byteUnit; byteUnit = ByteUnit.valueOf(arg); System.out.println(Configuration.getBytes(key) / byteUnit.getValue()); break; } catch (Exception e) { // try next unit parse } try { TimeUnit timeUnit; timeUnit = TimeUnit.valueOf(arg); System.out.println(Configuration.getMs(key) / timeUnit.getValue()); break; } catch (IllegalArgumentException ex) { // try next unit parse } printHelp(String.format("%s is not a valid unit", arg)); return 1; } else { System.out.println(Configuration.get(key)); } } break; default: printHelp("More arguments than expected"); return 1; } return 0; }
From source file:de.uni_siegen.wineme.come_in.thumbnailer.Main.java
private static void parseParams(String[] params) { CommandLineParser parser = new GnuParser(); CommandLine line = null; try {// ww w . ja v a 2s. c om line = parser.parse(options, params); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); explainUsage(); System.exit(1); } if (line.hasOption("size")) { // TODO Set } String[] files = line.getArgs(); if (files.length == 0 || files.length > 2) { explainUsage(); System.exit(1); } inFile = new File(files[0]); if (files.length > 1) outFile = new File(files[1]); }
From source file:jettyClient.simpleClient.Parameters.java
/** * Check if the given parameters are correct. * //ww w. jav a2 s .co m * @param line * Command line arguments. * @return Configuration options for the client. */ private static ClientOptions setOptions(CommandLine line) { URL spURL = null; // Create the configuration for the client. ClientOptions options = new ClientOptions(); // Get the arguments not matching options. String leftoverArgs[] = line.getArgs(); // If there is an SP given. if (leftoverArgs.length > 0) { // Parse the SP URL spURL = getURL(leftoverArgs[0]); // // Set the IdP ID // options.setIdpID(leftoverArgs[1]); } else { System.out.println("SP endpoint missing. Usage: " + usage); System.out.println( "Example: java -jar simpleClient.jar http://localhost:8443/initiateECP some-shibboleth-idp-id"); } // Prints help if the SP URL has failed. if (spURL != null) { options.setSpURL(spURL); } else { System.out.println("Invalid SP URL."); System.out.println("Usage: " + usage); System.out.println( "Example: java -jar simpleClient.jar http://localhost:8443/initiateECP some-shibboleth-idp-id"); System.exit(1); } // Save the idp-id. if (line.hasOption(idpID)) { options.setIdpID(line.getOptionValue(idpID)); logger.debug("Using IdP id: " + idpID); } else { System.out.println("No IdP id specified."); System.out.println("Usage: " + usage); System.out.println( "Example: java -jar simpleClient.jar http://localhost:8443/initiateECP some-shibboleth-idp-id"); System.exit(1); } // Verbose if (line.hasOption(verbose)) { options.setVerbose(true); logger.debug("Verbose mode activated."); } // SP Endpoint if (line.hasOption(spEndpoint)) { String endpointValue = line.getOptionValue(spEndpoint); URL endpoint = getURL(endpointValue); options.setSpEndpoint(endpoint); logger.debug("The endpoint URL is : " + endpointValue); if (endpoint == null) { System.out.println("Invalid SP endpoint URL: " + endpointValue); System.exit(1); } } return options; }
From source file:com.zimbra.cs.util.ProxyPurgeUtil.java
/** Extract the account names * @param commandLine Command Line object (org.apache.commons.cli.CommandLine) * @return An ArrayList containing the server names specified in the command line *//* www. ja v a2s. c o m*/ static ArrayList<String> getCacheServers(CommandLine commandLine) { ArrayList<String> servers = new ArrayList<String>(); String[] values = commandLine.getArgs(); if (values != null) { for (String s : commandLine.getArgs()) { servers.add(s); } } return servers; }