Example usage for org.apache.commons.cli HelpFormatter printHelp

List of usage examples for org.apache.commons.cli HelpFormatter printHelp

Introduction

In this page you can find the example usage for org.apache.commons.cli HelpFormatter printHelp.

Prototype

public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer,
        boolean autoUsage) 

Source Link

Document

Print the help for options with the specified command line syntax.

Usage

From source file:net.sf.jsignpdf.verify.SignatureCounter.java

/**
 * Main program.//from  w w w .j a v  a  2s .c o  m
 * 
 * @param args
 */
public static void main(String[] args) {

    // create the Options
    final Option optHelp = new Option("h", "help", false, "print this message");
    final Option optDebug = new Option("d", "debug", false, "enables debug output");
    final Option optNames = new Option("n", "names", false,
            "print comma separated signature names instead of the count");
    final Option optPasswd = new Option("p", "password", true, "set password for opening PDF");
    optPasswd.setArgName("password");

    final Options options = new Options();
    options.addOption(optHelp);
    options.addOption(optDebug);
    options.addOption(optNames);
    options.addOption(optPasswd);

    CommandLine line = null;
    try {
        // create the command line parser
        CommandLineParser parser = new PosixParser();
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Unable to parse command line (Use -h for the help)\n" + exp.getMessage());
        System.exit(Constants.EXIT_CODE_PARSE_ERR);
    }

    final String[] tmpArgs = line.getArgs();
    if (line.hasOption("h") || args == null || args.length == 0) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(70, "java -jar SignatureCounter.jar [file1.pdf [file2.pdf ...]]",
                "JSignPdf SignatureCounter is a command line tool which prints count of signatures in given PDF document.",
                options, null, true);
    } else {
        byte[] tmpPasswd = null;
        if (line.hasOption("p")) {
            tmpPasswd = line.getOptionValue("p").getBytes();
        }
        final boolean debug = line.hasOption("d");
        final boolean names = line.hasOption("n");

        for (String tmpFilePath : tmpArgs) {
            if (debug) {
                System.out.print("Counting signatures in " + tmpFilePath + ": ");
            }
            final File tmpFile = new File(tmpFilePath);
            if (!tmpFile.canRead()) {
                System.err.println("Couldn't read the file. Check the path and permissions: " + tmpFilePath);
                System.exit(Constants.EXIT_CODE_CANT_READ_FILE);
            }
            try {
                final PdfReader pdfReader = PdfUtils.getPdfReader(tmpFilePath, tmpPasswd);
                @SuppressWarnings("unchecked")
                final List<String> sigNames = pdfReader.getAcroFields().getSignatureNames();
                if (names) {
                    //print comma-separated names
                    boolean isNotFirst = false;
                    for (String sig : sigNames) {
                        if (isNotFirst) {
                            System.out.println(",");
                        } else {
                            isNotFirst = true;
                        }
                        System.out.println(sig);
                    }
                } else {
                    //normal processing print only count of signatures
                    System.out.println(sigNames.size());
                    if (debug) {
                        System.out.println("Signature names: " + sigNames);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(Constants.EXIT_CODE_COMMON_ERROR);
            }
        }
    }
}

From source file:eu.fbk.utils.twm.FormPageSearcher.java

public static void main(final String args[]) throws Exception {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "configuration/log-config.txt";
    }//from   w  w w  .  j  av  a  2  s . co m

    PropertyConfigurator.configure(logConfig);
    final Options options = new Options();
    try {
        OptionBuilder.withArgName("index");
        OptionBuilder.hasArg();
        OptionBuilder.withDescription("open an index with the specified name");
        OptionBuilder.isRequired();
        OptionBuilder.withLongOpt("index");
        final Option indexNameOpt = OptionBuilder.create("i");
        OptionBuilder.withArgName("interactive-mode");
        OptionBuilder.withDescription("enter in the interactive mode");
        OptionBuilder.withLongOpt("interactive-mode");
        final Option interactiveModeOpt = OptionBuilder.create("t");
        OptionBuilder.withArgName("search");
        OptionBuilder.hasArg();
        OptionBuilder.withDescription("search for the specified key");
        OptionBuilder.withLongOpt("search");
        final Option searchOpt = OptionBuilder.create("s");
        OptionBuilder.withArgName("key-freq");
        OptionBuilder.hasArg();
        OptionBuilder.withDescription("read the keys' frequencies from the specified file");
        OptionBuilder.withLongOpt("key-freq");
        final Option freqFileOpt = OptionBuilder.create("f");
        OptionBuilder.withArgName("minimum-freq");
        // Option keyFieldNameOpt =
        // OptionBuilder.withArgName("key-field-name").hasArg().withDescription("use the specified name for the field key").withLongOpt("key-field-name").create("k");
        // Option valueFieldNameOpt =
        // OptionBuilder.withArgName("value-field-name").hasArg().withDescription("use the specified name for the field value").withLongOpt("value-field-name").create("v");
        final Option minimumKeyFreqOpt = OptionBuilder.hasArg()
                .withDescription("minimum key frequency of cached values (default is " + DEFAULT_MIN_FREQ + ")")
                .withLongOpt("minimum-freq").create("m");
        OptionBuilder.withArgName("int");
        final Option notificationPointOpt = OptionBuilder.hasArg()
                .withDescription(
                        "receive notification every n pages (default is " + DEFAULT_NOTIFICATION_POINT + ")")
                .withLongOpt("notification-point").create("b");
        options.addOption("h", "help", false, "print this message");
        options.addOption("v", "version", false, "output version information and exit");

        options.addOption(indexNameOpt);
        options.addOption(interactiveModeOpt);
        options.addOption(searchOpt);
        options.addOption(freqFileOpt);
        // options.addOption(keyFieldNameOpt);
        // options.addOption(valueFieldNameOpt);
        options.addOption(minimumKeyFreqOpt);
        options.addOption(notificationPointOpt);

        final CommandLineParser parser = new PosixParser();
        final CommandLine line = parser.parse(options, args);

        if (line.hasOption("help") || line.hasOption("version")) {
            throw new ParseException("");
        }

        int minFreq = DEFAULT_MIN_FREQ;
        if (line.hasOption("minimum-freq")) {
            minFreq = Integer.parseInt(line.getOptionValue("minimum-freq"));
        }

        int notificationPoint = DEFAULT_NOTIFICATION_POINT;
        if (line.hasOption("notification-point")) {
            notificationPoint = Integer.parseInt(line.getOptionValue("notification-point"));
        }

        final FormPageSearcher pageFormSearcher = new FormPageSearcher(line.getOptionValue("index"));
        pageFormSearcher.setNotificationPoint(notificationPoint);
        /*
         * logger.debug(line.getOptionValue("key-field-name") + "\t" +
         * line.getOptionValue("value-field-name")); if (line.hasOption("key-field-name")) {
         * pageFormSearcher.setKeyFieldName(line.getOptionValue("key-field-name")); } if
         * (line.hasOption("value-field-name")) {
         * pageFormSearcher.setValueFieldName(line.getOptionValue("value-field-name")); }
         */
        if (line.hasOption("key-freq")) {
            pageFormSearcher.loadCache(line.getOptionValue("key-freq"), minFreq);
        }
        if (line.hasOption("search")) {
            logger.debug("searching " + line.getOptionValue("search") + "...");
            final FreqSetSearcher.Entry[] result = pageFormSearcher.search(line.getOptionValue("search"));
            logger.info(Arrays.toString(result));
        }
        if (line.hasOption("interactive-mode")) {
            pageFormSearcher.interactive();
        }
    } catch (final ParseException e) {
        // oops, something went wrong
        if (e.getMessage().length() > 0) {
            System.out.println("Parsing failed: " + e.getMessage() + "\n");
        }
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(400,
                "java -cp dist/thewikimachine.jar org.fbk.cit.hlt.thewikimachine.index.FormPageSearcher", "\n",
                options, "\n", true);
    }
}

From source file:eu.fbk.utils.wikipedia.WikipediaPlainTextExtractor.java

public static void main(String args[]) throws IOException {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "configuration/log-config.txt";
    }//from   w ww  .  j av a  2 s. c  o  m

    PropertyConfigurator.configure(logConfig);

    Options options = new Options();
    try {
        Option wikipediaDumpOpt = OptionBuilder.withArgName("file").hasArg()
                .withDescription("wikipedia xml dump file").isRequired().withLongOpt("wikipedia-dump")
                .create("d");
        Option outputDirOpt = OptionBuilder.withArgName("dir").hasArg()
                .withDescription("output directory in which to store output files").isRequired()
                .withLongOpt("output-dir").create("o");
        Option numThreadOpt = OptionBuilder.withArgName("int").hasArg()
                .withDescription("number of threads (default " + Defaults.DEFAULT_THREADS_NUMBER + ")")
                .withLongOpt("num-threads").create("t");
        Option numPageOpt = OptionBuilder.withArgName("int").hasArg()
                .withDescription("number of pages to process (default all)").withLongOpt("num-pages")
                .create("p");
        Option notificationPointOpt = OptionBuilder.withArgName("int").hasArg()
                .withDescription("receive notification every n pages (default "
                        + Defaults.DEFAULT_NOTIFICATION_POINT + ")")
                .withLongOpt("notification-point").create("b");

        options.addOption(null, "text-only", false, "skipt title in file");

        options.addOption("h", "help", false, "print this message");
        options.addOption("v", "version", false, "output version information and exit");

        options.addOption(wikipediaDumpOpt);
        options.addOption(outputDirOpt);
        options.addOption(numThreadOpt);
        options.addOption(numPageOpt);
        options.addOption(notificationPointOpt);
        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, args);
        logger.debug(line);

        if (line.hasOption("help") || line.hasOption("version")) {
            throw new ParseException("");
        }

        int numThreads = Defaults.DEFAULT_THREADS_NUMBER;
        boolean textOnly = line.hasOption("text-only");
        if (line.hasOption("num-threads")) {
            numThreads = Integer.parseInt(line.getOptionValue("num-threads"));
        }

        int numPages = Defaults.DEFAULT_NUM_PAGES;
        if (line.hasOption("num-pages")) {
            numPages = Integer.parseInt(line.getOptionValue("num-pages"));
        }

        int notificationPoint = Defaults.DEFAULT_NOTIFICATION_POINT;
        if (line.hasOption("notification-point")) {
            notificationPoint = Integer.parseInt(line.getOptionValue("notification-point"));
        }

        ExtractorParameters extractorParameters = new ExtractorParameters(line.getOptionValue("wikipedia-dump"),
                line.getOptionValue("output-dir"));
        WikipediaPlainTextExtractor wikipediaPageParser = new WikipediaPlainTextExtractor(numThreads, numPages,
                extractorParameters.getLocale());
        wikipediaPageParser.setNotificationPoint(notificationPoint);
        //            wikipediaPageParser.setSkipTitle(textOnly);
        wikipediaPageParser.start(extractorParameters);

        logger.info("extraction ended " + new Date());

    } catch (ParseException e) {
        // oops, something went wrong
        System.out.println("Parsing failed: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(400,
                "java -cp dist/thewikimachine.jar org.fbk.cit.hlt.thewikimachine.xmldump.WikipediaTextExtractor",
                "\n", options, "\n", true);
    }
}

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  ww .j  av a 2 s  .  c  o  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.sf.jsignpdf.verify.Verifier.java

/**
 * @param args//from w  ww. ja v a  2  s .c  o m
 */
public static void main(String[] args) {

    // create the Options
    Option optHelp = new Option("h", "help", false, "print this message");
    // Option optVersion = new Option("v", "version", false,
    // "print version info");
    Option optCerts = new Option("c", "cert", true, "use external semicolon separated X.509 certificate files");
    optCerts.setArgName("certificates");
    Option optPasswd = new Option("p", "password", true, "set password for opening PDF");
    optPasswd.setArgName("password");
    Option optExtract = new Option("e", "extract", true, "extract signed PDF revisions to given folder");
    optExtract.setArgName("folder");
    Option optListKs = new Option("lk", "list-keystore-types", false, "list keystore types provided by java");
    Option optListCert = new Option("lc", "list-certificates", false, "list certificate aliases in a KeyStore");
    Option optKsType = new Option("kt", "keystore-type", true, "use keystore type with given name");
    optKsType.setArgName("keystore_type");
    Option optKsFile = new Option("kf", "keystore-file", true, "use given keystore file");
    optKsFile.setArgName("file");
    Option optKsPass = new Option("kp", "keystore-password", true,
            "password for keystore file (look on -kf option)");
    optKsPass.setArgName("password");
    Option optFailFast = new Option("ff", "fail-fast", false,
            "flag which sets the Verifier to exit with error code on the first validation failure");

    final Options options = new Options();
    options.addOption(optHelp);
    // options.addOption(optVersion);
    options.addOption(optCerts);
    options.addOption(optPasswd);
    options.addOption(optExtract);
    options.addOption(optListKs);
    options.addOption(optListCert);
    options.addOption(optKsType);
    options.addOption(optKsFile);
    options.addOption(optKsPass);
    options.addOption(optFailFast);

    CommandLine line = null;
    try {
        // create the command line parser
        CommandLineParser parser = new PosixParser();
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Illegal command used: " + exp.getMessage());
        System.exit(SignatureVerification.SIG_STAT_CODE_ERROR_UNEXPECTED_PROBLEM);
    }

    final boolean failFast = line.hasOption("ff");
    final String[] tmpArgs = line.getArgs();
    if (line.hasOption("h") || args == null || args.length == 0) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(70, "java -jar Verifier.jar [file1.pdf [file2.pdf ...]]",
                "JSignPdf Verifier is a command line tool for verifying signed PDF documents.", options, null,
                true);
    } else if (line.hasOption("lk")) {
        // list keystores
        for (String tmpKsType : KeyStoreUtils.getKeyStores()) {
            System.out.println(tmpKsType);
        }
    } else if (line.hasOption("lc")) {
        // list certificate aliases in the keystore
        for (String tmpCert : KeyStoreUtils.getCertAliases(line.getOptionValue("kt"), line.getOptionValue("kf"),
                line.getOptionValue("kp"))) {
            System.out.println(tmpCert);
        }
    } else {
        final VerifierLogic tmpLogic = new VerifierLogic(line.getOptionValue("kt"), line.getOptionValue("kf"),
                line.getOptionValue("kp"));
        tmpLogic.setFailFast(failFast);

        if (line.hasOption("c")) {
            String tmpCertFiles = line.getOptionValue("c");
            for (String tmpCFile : tmpCertFiles.split(";")) {
                tmpLogic.addX509CertFile(tmpCFile);
            }
        }
        byte[] tmpPasswd = null;
        if (line.hasOption("p")) {
            tmpPasswd = line.getOptionValue("p").getBytes();
        }
        String tmpExtractDir = null;
        if (line.hasOption("e")) {
            tmpExtractDir = new File(line.getOptionValue("e")).getPath();
        }

        int exitCode = 0;

        for (String tmpFilePath : tmpArgs) {
            int exitCodeForFile = 0;
            System.out.println("Verifying " + tmpFilePath);
            final File tmpFile = new File(tmpFilePath);
            if (!tmpFile.canRead()) {
                exitCodeForFile = SignatureVerification.SIG_STAT_CODE_ERROR_FILE_NOT_READABLE;
                System.err.println("Couln't read the file. Check the path and permissions.");
                if (failFast) {
                    System.exit(exitCodeForFile);
                }
                exitCode = Math.max(exitCode, exitCodeForFile);
                continue;
            }
            final VerificationResult tmpResult = tmpLogic.verify(tmpFilePath, tmpPasswd);
            if (tmpResult.getException() != null) {
                tmpResult.getException().printStackTrace();
                exitCodeForFile = SignatureVerification.SIG_STAT_CODE_ERROR_UNEXPECTED_PROBLEM;
                if (failFast) {
                    System.exit(exitCodeForFile);
                }
                exitCode = Math.max(exitCode, exitCodeForFile);
                continue;
            } else {
                System.out.println("Total revisions: " + tmpResult.getTotalRevisions());
                for (SignatureVerification tmpSigVer : tmpResult.getVerifications()) {
                    System.out.println(tmpSigVer.toString());
                    if (tmpExtractDir != null) {
                        try {
                            File tmpExFile = new File(tmpExtractDir + "/" + tmpFile.getName() + "_"
                                    + tmpSigVer.getRevision() + ".pdf");
                            System.out.println("Extracting to " + tmpExFile.getCanonicalPath());
                            FileOutputStream tmpFOS = new FileOutputStream(tmpExFile.getCanonicalPath());

                            InputStream tmpIS = tmpLogic.extractRevision(tmpFilePath, tmpPasswd,
                                    tmpSigVer.getName());
                            IOUtils.copy(tmpIS, tmpFOS);
                            tmpIS.close();
                            tmpFOS.close();
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                        }
                    }
                }
                exitCodeForFile = tmpResult.getVerificationResultCode();
                if (failFast && SignatureVerification.isError(exitCodeForFile)) {
                    System.exit(exitCodeForFile);
                }
            }
            exitCode = Math.max(exitCode, exitCodeForFile);
        }
        if (exitCode != 0 && tmpArgs.length > 1) {
            System.exit(SignatureVerification.isError(exitCode)
                    ? SignatureVerification.SIG_STAT_CODE_ERROR_ANY_ERROR
                    : SignatureVerification.SIG_STAT_CODE_WARNING_ANY_WARNING);
        } else {
            System.exit(exitCode);
        }
    }
}

From source file:jlite.cli.ProxyDelegate.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();//from w  w  w.j av  a 2  s . com
    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 != null) && (line.hasOption("xml"))) {
            System.out.println("<error>" + e.getMessage() + "</error>");
        } else {
            System.err.println(e.getMessage());
        }
    } finally {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:jlite.cli.ProxyInfo.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();/*from  w w  w .  ja va 2s. com*/
    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 + "\n", 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 + "\n", 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 {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:jlite.cli.JobCancel.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();/*from  www .j  a  va 2 s. c  om*/
    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);
        } else {
            if (line.hasOption("xml")) {
                System.out.println("<output>");
            }
            run(line.getArgs(), 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 {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:jlite.cli.JobMatch.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();//from   w  w  w. j av a 2  s  . c  om
    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);
        } else {
            if (line.hasOption("xml")) {
                System.out.println("<output>");
            }
            String[] remArgs = line.getArgs();
            if (remArgs.length == 1) {
                run(remArgs[0], line);
            } else if (remArgs.length == 0) {
                throw new MissingArgumentException("Missing required argument: <jdl_file>");
            } else {
                throw new UnrecognizedOptionException("Unrecognized extra arguments");
            }
        }
    } 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 {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:jlite.cli.JobSubmit.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();/*from  ww w  . j  a va  2  s .c om*/
    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 + "\n", false);
            System.out.println(); // extra line
            System.exit(0);
        } else {
            if (line.hasOption("xml")) {
                System.out.println("<output>");
            }
            String[] remArgs = line.getArgs();
            if (remArgs.length == 1) {
                run(remArgs[0], line);
            } else if (remArgs.length == 0) {
                throw new MissingArgumentException("Missing required argument: <jdl_file>");
            } else {
                throw new UnrecognizedOptionException("Unrecognized extra arguments");
            }
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage() + "\n");
        helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", 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 {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}