List of usage examples for org.apache.commons.cli GnuParser GnuParser
GnuParser
From source file:com.mosso.client.cloudfiles.sample.FilesMakeContainer.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);//from www . j a va2 s.c o m CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); String containerName = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); createContaier(containerName); } //end if (line.hasOption("container")) else if (args.length > 0) { //If we got this far there are command line arguments but none of what we expected treat the first one as the Container name containerName = args[0]; createContaier(containerName); } else { System.err.println("You must provide the -container with a valid value for this to work !"); System.exit(-1); } } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (IOException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesMakeContainer.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);// ww w .j a va2 s. c om CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); String containerName = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); createContaier(containerName); } //end if (line.hasOption("container")) else if (args.length > 0) { //If we got this far there are command line arguments but none of what we expected treat the first one as the Container name containerName = args[0]; createContaier(containerName); } else { System.err.println("You must provide the -container with a valid value for this to work !"); System.exit(-1); } } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (Exception err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.mosso.client.cloudfiles.sample.FilesRemove.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/*w w w.jav a 2 s. c om*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { printHelp(options); System.exit(0); } if (line.hasOption("container")) { String containerName = null; containerName = line.getOptionValue("container"); removeContainer(containerName, line.hasOption('r')); } //if (line.hasOption("container")) if (line.hasOption("object")) { String ObjectNameWithPath = null; ObjectNameWithPath = line.getOptionValue("object"); removeObject(ObjectNameWithPath); } //if (line.hasOption("container")) } //end try catch (ParseException err) { logger.fatal("Parsing exception on the command line: " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (IOException err) { logger.fatal("IOException : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesRemove.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/*from www .j av a 2 s . c om*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { printHelp(options); System.exit(0); } if (line.hasOption("container")) { String containerName = null; containerName = line.getOptionValue("container"); removeContainer(containerName, line.hasOption('r')); } //if (line.hasOption("container")) if (line.hasOption("object")) { String ObjectNameWithPath = null; ObjectNameWithPath = line.getOptionValue("object"); removeObject(ObjectNameWithPath); } //if (line.hasOption("container")) } //end try catch (ParseException err) { logger.fatal("Parsing exception on the command line: " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (Exception err) { logger.fatal("Exception : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.contentful.generator.Main.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = constructOptions(); try {/* w ww. jav a 2s . c om*/ CommandLine line = parser.parse(options, args); if (line.hasOption("space") && line.hasOption("package") && line.hasOption("folder") && line.hasOption("token")) { new Generator().generate(line.getOptionValue("space"), line.getOptionValue("package"), line.getOptionValue("folder"), line.getOptionValue("token")); } else { usage(options); } } catch (ParseException e) { System.err.println("Parsing failed, reason: " + e.getMessage()); } }
From source file:net.hedges.fandangled.commandline.GenericCli.java
public static void main(String[] args) { options = buildOptions();/*from ww w .java2 s.c om*/ try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); verbose = line.hasOption('v'); if (line.hasOption('h')) { usage(); System.exit(0); } String template = line.getOptionValue("templates"); String input = line.getOptionValue("input"); String output = line.getOptionValue("output"); String prefix = line.getOptionValue("prefix", ""); String extension = line.getOptionValue("extension", ".txt"); File inputFile = new File(input); File outputDir = new File(output); File templateDir = new File(template); checkFilesAndDirectories(inputFile, outputDir, templateDir); GenericCodec codec = new GenericCodec(); codec.setTemplatePath(templateDir.getAbsolutePath()); codec.setExtension(extension); codec.setPrefix(prefix); Interface _interface = InterfaceBuilder.parse(inputFile); codec.encode(_interface, outputDir); } catch (ParseException e) { System.err.print(e.getMessage() + "\n"); usage(); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.interedition.collatex.tools.CollateX.java
public static void main(String... args) { try {//from w ww. j a v a 2s .c o m final CommandLine commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption("h")) { help(); } else if (commandLine.hasOption("S")) { CollationServer.start(commandLine); } else { CollationPipe.start(commandLine); } } catch (ParseException e) { error("Error while parsing command line arguments (-h for usage instructions)", e); } catch (IllegalArgumentException e) { error("Illegal argument", e); } catch (IOException e) { error("I/O error", e); } catch (SAXException e) { error("XML error", e); } catch (XPathExpressionException e) { error("XPath error", e); } catch (ScriptException | PluginScript.PluginScriptExecutionException e) { error("Script error", e); } catch (Throwable t) { error("Unexpected error", t); t.printStackTrace(ERROR_LOG); } finally { ERROR_LOG.flush(); } }
From source file:jlite.cli.ProxyDestroy.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/*from w w w .j a va 2 s. co m*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } if (line.hasOption("xml")) { System.out.println("<output>"); } run(line); } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { System.out.println("</output>"); } System.out.println(); // extra line }
From source file:net.ninjacat.stubborn.Stubborn.java
public static void main(String[] argv) throws ClassNotFoundException, ParseException { Options options = createOptions();/*from www .j a v a2 s. com*/ if (argv.length == 0) { printHelp(options); return; } Class.forName(Bootstrapper.class.getCanonicalName()); CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, argv); if (commandLine.hasOption("h")) { printHelp(options); return; } Context context = new Context(commandLine); Transformer transformer = Bootstrapper.get(Transformer.class); transformer.transform(context); } catch (MissingOptionException ex) { System.out.println("Missing required parameter " + ex.getMissingOptions()); printHelp(options); } catch (TransformationException ex) { System.out.println("Failed to perform transformation caused by " + ex.getCause()); System.out.println(ex.getMessage()); } }
From source file:com.mosso.client.cloudfiles.sample.FilesList.java
public static void main(String args[]) { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/*from w ww. j a va2 s . c om*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); if (line.hasOption("containersOnly")) { if (line.hasOption("H")) printContainers(true); else printContainers(false); } else if (line.hasOption("all")) { if (line.hasOption("H")) printContainersAll(true); else printContainersAll(false); } //if (line.hasOption("all")) else if (line.hasOption("container")) { String containerName = line.getOptionValue("container"); if (StringUtils.isNotBlank(containerName)) { if (line.hasOption("H")) printContainer(containerName, true); else printContainer(containerName, false); } } //if (line.hasOption("container")) else if (line.hasOption("H")) { System.out.println( "This option needs to be used in conjunction with another option that lists objects or container."); } } catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (FilesException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch (FilesAuthorizationException err) catch (IOException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }