List of usage examples for org.apache.commons.cli Option toString
public String toString()
From source file:io.stpettersen.bluejpackager.BlueJPackager.java
private static void displayUsage(Options options, int exitCode) { System.out.println("\nBlueJ Packager."); System.out.println("Utility to morph a BlueJ project into a structured Java package."); System.out.println("\nCopyright (c) 2016 Sam Saint-Pettersen."); System.out.println("Released under the MIT License.\n"); for (Option opt : options.getOptions()) { String[] fopt = opt.toString().split("::", 3); System.out.println(fopt[0].replace("[ option: ", "-") + ":" + fopt[1]); }//w ww. jav a 2 s .co m System.out.println(""); System.exit(exitCode); }
From source file:de.yaio.commons.cli.CmdLineJob.java
/** * do the jobprocessing/*from w w w . j a v a 2s .c o m*/ * <ul> * <li>initialize CmdLineHelper and Commandline * <li>call initJob * <li>call doJob * <li>call cleanUpAfterJob * </ul> */ public void startJobProcessing() { try { // config cmdArgs LOGGER.info("configure CmdArgs"); Options newAvailiableCmdLineOptions = this.addAvailiableCmdLineOptions(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("startJobProcessing: " + "add commandLineOptions:" + newAvailiableCmdLineOptions); } this.getCmdLineHelper().addAvailiableCmdLineOptions(newAvailiableCmdLineOptions); // parse cmdArgs LOGGER.info("initCommandLine"); this.getCmdLineHelper().getCommandLine(); // check for unknown Args String strCmdLineArgs = ""; for (String arg : this.getCmdLineHelper().getCmdLineArgs()) { strCmdLineArgs += ", " + arg; } LOGGER.info("used CmdLineArgs: " + strCmdLineArgs); if (this.getCmdLineHelper().getCommandLine() != null) { strCmdLineArgs = ""; for (String arg : this.getCmdLineHelper().getCommandLine().getArgs()) { strCmdLineArgs += ", " + arg; } LOGGER.info("unknown CmdLineArgs: " + strCmdLineArgs); strCmdLineArgs = ""; for (Option option : this.getCmdLineHelper().getCommandLine().getOptions()) { strCmdLineArgs += ", " + option.toString(); } LOGGER.info("used Options: " + strCmdLineArgs); } // validate cmdLine LOGGER.info("validate CmdLine"); if (!this.getCmdLineHelper().validateCmdLine()) { logErrorMsg("Illegal CmdArgs: print Usage"); this.printUsage(); LOGGER.info("Exit: 1"); System.exit(CONST_EXITCODE_FAILED_ARGS); } // print Usage if (this.getCmdLineHelper().getCommandLine().hasOption("h")) { LOGGER.info("print Usage"); this.printUsage(); LOGGER.info("Exit: " + CONST_EXITCODE_OK); System.exit(CONST_EXITCODE_OK); } // set debug if (this.getCmdLineHelper().getCommandLine().hasOption("debug")) { LOGGER.info("activate debug"); Logger.getRootLogger().setLevel(org.apache.log4j.Level.ALL); } LOGGER.info("start initJob"); this.initJob(); LOGGER.info("done initJob"); LOGGER.info("start doJob"); this.doJob(); LOGGER.info("done doJob"); LOGGER.info("start cleanUpAfterJob"); this.cleanUpAfterJob(); LOGGER.info("done cleanUpAfterJob"); } catch (Throwable e) { // Catch Error try { LOGGER.info("start cleanUpAfterJob when Error"); this.cleanUpAfterJob(); LOGGER.info("done cleanUpAfterJob when Error"); } catch (Throwable e2) { // Log Error while cleanUp this.handleThrowable(e2, false); } // Log Error this.handleThrowable(e, true); } }