List of usage examples for org.apache.commons.cli ParseException printStackTrace
public void printStackTrace(PrintStream s)
From source file:com.navercorp.client.Main.java
public static void main(String[] args) { Client clnt = null;//from ww w .j a va2 s. c o m try { CommandLine cmd = new DefaultParser() .parse(new Options().addOption("z", true, "zookeeper address (ip:port,ip:port,...)") .addOption("t", true, "zookeeper connection timeout") .addOption("c", true, "command and arguments"), args); final String connectionString = cmd.hasOption("z") ? cmd.getOptionValue("z") : "127.0.0.1:2181"; final int timeout = cmd.hasOption("t") ? Integer.valueOf(cmd.getOptionValue("t")) : 10000; clnt = new Client(connectionString, timeout); String command; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while ((command = in.readLine()) != null) { printResult(clnt.execute(command.split(" "))); } System.exit(Code.OK.n()); } catch (ParseException e) { e.printStackTrace(System.err); System.err.println(Client.getUsage()); System.exit(INVALID_ARGUMENT.n()); } catch (IOException e) { e.printStackTrace(System.err); System.exit(ZK_CONNECTION_LOSS.n()); } catch (InterruptedException e) { e.printStackTrace(System.err); System.exit(INTERNAL_ERROR.n()); } finally { if (clnt != null) { try { clnt.close(); } catch (Exception e) { ; // nothing to do } } } }
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 w ww . j a v a2 s .co 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);/*from w ww . j a v a 2 s .com*/ 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.zimbra.cs.store.file.BlobDeduperUtil.java
public static void main(String[] args) { BlobDeduperUtil app = new BlobDeduperUtil(); try {//from www. j a v a 2s. c o m app.parseArgs(args); } catch (ParseException e) { app.usage(e.getMessage()); } try { app.run(); } catch (Exception e) { if (app.verbose) { e.printStackTrace(new PrintWriter(System.err, true)); } else { String msg = e.getMessage(); if (msg == null) { msg = e.toString(); } System.err.println(msg); } System.exit(1); } }
From source file:de.burlov.amazon.s3.S3Utils.java
public static void main(String[] args) { Options opts = new Options(); OptionGroup gr = new OptionGroup(); gr.setRequired(true);//from ww w . ja v a2s .c o m gr.addOption(new Option(LIST, false, "")); gr.addOption(new Option(DELETE, false, "")); opts.addOptionGroup(gr); opts.addOption(new Option("k", true, "Access key for AWS account")); opts.addOption(new Option("s", true, "Secret key for AWS account")); opts.addOption(new Option("b", true, "Bucket")); CommandLine cmd = null; try { cmd = new PosixParser().parse(opts, args); String accessKey = cmd.getOptionValue("k"); if (StringUtils.isBlank(accessKey)) { System.out.println("Missing amazon access key"); return; } String secretKey = cmd.getOptionValue("s"); if (StringUtils.isBlank(secretKey)) { System.out.println("Missing secret key"); return; } String bucket = cmd.getOptionValue("b"); if (cmd.hasOption(LIST)) { if (StringUtils.isBlank(bucket)) { printBuckets(accessKey, secretKey); } else { printBucket(accessKey, secretKey, bucket); } } else if (cmd.hasOption(DELETE)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } int count = deleteBucket(accessKey, secretKey, bucket); System.out.println("Deleted objects in bucket: " + count); } } catch (ParseException e) { System.out.println(e.getMessage()); printUsage(opts); return; } catch (Exception e) { e.printStackTrace(System.err); } }
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);// w w w . j av a 2 s. co m 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) }
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);//from w w w.j a va 2 s . co m 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 w ww . j ava 2 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); 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.rackspacecloud.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 w w . j av a 2 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); 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 (HttpException 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.zimbra.cs.store.file.BlobConsistencyUtil.java
public static void main(String[] args) { BlobConsistencyUtil app = new BlobConsistencyUtil(); try {/*from www .j a va 2 s. co m*/ app.parseArgs(args); } catch (ParseException e) { app.usage(e.getMessage()); } try { app.run(); } catch (Exception e) { if (app.verbose) { e.printStackTrace(new PrintWriter(System.err, true)); } else { String msg = e.getMessage(); if (msg == null) { msg = e.toString(); } System.err.println(msg); } System.exit(1); } }