List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:com.dasasian.chok.tool.ZkTool.java
public static void main(String[] args) { final Options options = new Options(); Option lsOption = new Option("ls", true, "list zp path contents"); lsOption.setArgName("path"); Option readOption = new Option("read", true, "read and print zp path contents"); readOption.setArgName("path"); Option rmOption = new Option("rm", true, "remove zk files"); rmOption.setArgName("path"); Option rmrOption = new Option("rmr", true, "remove zk directories"); rmrOption.setArgName("path"); OptionGroup actionGroup = new OptionGroup(); actionGroup.setRequired(true);//from w w w .jav a 2 s . co m actionGroup.addOption(lsOption); actionGroup.addOption(readOption); actionGroup.addOption(rmOption); actionGroup.addOption(rmrOption); options.addOptionGroup(actionGroup); final CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); try { final CommandLine line = parser.parse(options, args); ZkTool zkTool = new ZkTool(); if (line.hasOption(lsOption.getOpt())) { String path = line.getOptionValue(lsOption.getOpt()); zkTool.ls(path); } else if (line.hasOption(readOption.getOpt())) { String path = line.getOptionValue(readOption.getOpt()); zkTool.read(path); } else if (line.hasOption(rmOption.getOpt())) { String path = line.getOptionValue(rmOption.getOpt()); zkTool.rm(path, false); } else if (line.hasOption(rmrOption.getOpt())) { String path = line.getOptionValue(rmrOption.getOpt()); zkTool.rm(path, true); } zkTool.close(); } catch (ParseException e) { System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage()); formatter.printHelp(ZkTool.class.getSimpleName(), options); } }
From source file:com.zimbra.cs.store.file.BlobDeduperUtil.java
public static void main(String[] args) { BlobDeduperUtil app = new BlobDeduperUtil(); try {/*ww w. j a v a2 s. 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:com.google.endpoints.examples.bookstore.BookstoreServer.java
public static void main(String[] args) throws Exception { Options options = createOptions();// w ww. j a v a2 s . c o m CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); printUsage(options); return; } int port = DEFAULT_PORT; if (line.hasOption("port")) { String portOption = line.getOptionValue("port"); try { port = Integer.parseInt(portOption); } catch (java.lang.NumberFormatException e) { System.err.println("Invalid port number: " + portOption); printUsage(options); return; } } final BookstoreData data = initializeBookstoreData(); final BookstoreServer server = new BookstoreServer(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { System.out.println("Shutting down"); server.stop(); } catch (Exception e) { e.printStackTrace(); } } }); server.start(port, data); System.out.format("Bookstore service listening on %d\n", port); server.blockUntilShutdown(); }
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 .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:de.mpi_bremen.mgg.FastaValidatorUi.java
/** * @param args the command line arguments *///from w w w . j a v a 2s . c o m public static void main(String[] args) { // create Options object Options options = new Options(); // add verbose option options.addOption("v", "verbose", false, "verbose mode"); // add inputfile option options.addOption("f", "file", true, "FASTA-formatted input file"); // add help option options.addOption("h", "help", false, "print this help message"); // add sequencetype option options.addOption("t", "seqtype", true, "sequence type (allowed values: all|dna|rna|protein)"); // add gui-mode option options.addOption("nogui", false, "start in non-interactive mode"); //create the cmdline-parser GnuParser parser = new GnuParser(); // parse the command line arguments try { //get cmdline arguments cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println(exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FastaValidatorUi", options, true); System.exit(1); //indicate error to external environment } if (cmdline.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FastaValidatorUi", options, true); System.exit(0); //indicate no errors to external environment } //which mode? (gui or cmdline) if (cmdline.hasOption("nogui")) { //cmdline-mode //create new cmdline-gui FvCmdline cmdlinegui = new FvCmdline(); //set verbosity cmdlinegui.setVerbose(cmdline.hasOption("v")); //handle input file if (cmdline.hasOption("f")) { cmdlinegui.setInput(cmdline.getOptionValue("f")); } //set sequencetype if (cmdline.hasOption("t")) { cmdlinegui.setSequencetype(getSeqtype(cmdline.getOptionValue("t"))); } else { cmdlinegui.setSequencetype(FastaValidator.Sequencetype.ALL); } //trigger validation and exit with exitcode int exitcode = cmdlinegui.validate().getValue(); System.exit(exitcode); } else { //gui-mode //start gui in its own thread SwingUtilities.invokeLater(new Runnable() { public void run() { FvGui w = new FvGui(); } }); } }
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);/* w w w . ja v a2 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 (Exception err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:cc.twittertools.corpus.demo.ReadStatuses.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input directory or file") .create(INPUT_OPTION));//from ww w . j a va 2s .co m options.addOption(VERBOSE_OPTION, false, "print logging output every 10000 tweets"); options.addOption(DUMP_OPTION, false, "dump statuses"); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ReadStatuses.class.getName(), options); System.exit(-1); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream; // Figure out if we're reading from HTML SequenceFiles or JSON. File file = new File(cmdline.getOptionValue(INPUT_OPTION)); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } if (file.isDirectory()) { stream = new JsonStatusCorpusReader(file); } else { stream = new JsonStatusBlockReader(file); } int cnt = 0; Status status; while ((status = stream.next()) != null) { if (cmdline.hasOption(DUMP_OPTION)) { String text = status.getText(); if (text != null) { text = text.replaceAll("\\s+", " "); text = text.replaceAll("\0", ""); } out.println(String.format("%d\t%s\t%s\t%s", status.getId(), status.getScreenname(), status.getCreatedAt(), text)); } cnt++; if (cnt % 10000 == 0 && cmdline.hasOption(VERBOSE_OPTION)) { LOG.info(cnt + " statuses read"); } } stream.close(); LOG.info(String.format("Total of %s statuses read.", cnt)); }
From source file:Compiler.java
/** A command line entry point to the mini Java compiler. *//*from w ww . j a v a2 s . c o m*/ public static void main(String[] args) { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("L", "LLVM", true, "LLVM Bitcode Output Location."); options.addOption("x", "x86", true, "x86 Output File Location"); options.addOption("l", "llvm", false, "Dump Human Readable LLVM Code."); options.addOption("i", "input", true, "Compile to x86 Assembly."); options.addOption("I", "interp", false, "Run the interpreter."); options.addOption("h", "help", false, "Print this help message."); options.addOption("V", "version", false, "Version information."); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { System.out.println("MiniJava Compiler"); System.out.println("Written By Mark Jones http://web.cecs.pdx.edu/~mpj/"); System.out.println("Extended for LLVM by Mitch Souders and Mark Smith"); } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar mjc.jar -i <INPUT> (--x86 <OUT>|--LLVM <OUT>|--llvm)", options); System.exit(0); } int errors = 0; if (!cmd.hasOption("i")) { System.out.println("-i|--input requires a MiniJava input file"); System.out.println("--help for more info."); errors++; } if (!cmd.hasOption("x") && !cmd.hasOption("l") && !cmd.hasOption("L") && !cmd.hasOption("I")) { System.out.println("--x86|--llvm|--LLVM|--interp required for some sort of output."); System.out.println("--help for more info."); errors++; } if (errors > 0) { System.exit(1); } String inputFile = cmd.getOptionValue("i"); compile(inputFile, cmd); } catch (ParseException exp) { System.out.println("Argument Error: " + exp.getMessage()); } }
From source file:com.soulgalore.crawler.run.CrawlToFile.java
/** * Run.//from www .java2 s .c o m * * @param args the args */ public static void main(String[] args) { try { final CrawlToFile crawl = new CrawlToFile(args); crawl.crawl(); } catch (ParseException e) { System.err.print(e.getMessage()); } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); } }
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramCount.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;//w ww. jav a 2s . c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramCount.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<Text, IntWritable>> bigrams = SequenceFileUtils.readDirectory(new Path(inputPath)); Collections.sort(bigrams, new Comparator<PairOfWritables<Text, IntWritable>>() { public int compare(PairOfWritables<Text, IntWritable> e1, PairOfWritables<Text, IntWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); int singletons = 0; int sum = 0; for (PairOfWritables<Text, IntWritable> bigram : bigrams) { sum += bigram.getRightElement().get(); if (bigram.getRightElement().get() == 1) { singletons++; } } System.out.println("total number of unique bigrams: " + bigrams.size()); System.out.println("total number of bigrams: " + sum); System.out.println("number of bigrams that appear only once: " + singletons); System.out.println("\nten most frequent bigrams: "); Iterator<PairOfWritables<Text, IntWritable>> iter = Iterators.limit(bigrams.iterator(), 10); while (iter.hasNext()) { PairOfWritables<Text, IntWritable> bigram = iter.next(); System.out.println(bigram.getLeftElement() + "\t" + bigram.getRightElement()); } }