List of usage examples for org.apache.commons.cli HelpFormatter DEFAULT_LEFT_PAD
int DEFAULT_LEFT_PAD
To view the source code for org.apache.commons.cli HelpFormatter DEFAULT_LEFT_PAD.
Click Source Link
From source file:at.peppol.smp.client.console.SMPClient.java
public static void main(final String[] args) throws Exception { if (false) {/*from ww w .j a v a 2s . co m*/ // Enable this section in development mode, if you want to trust all HTTPS // certificates final SSLContext aSSLContext = SSLContext.getInstance("SSL"); aSSLContext.init(null, new TrustManager[] { new DoNothingTrustManager() }, VerySecureRandom.getInstance()); HttpsURLConnection.setDefaultSSLSocketFactory(aSSLContext.getSocketFactory()); } final SMPClientOptions aOptions = new SMPClientOptions(); final CommandLine cmd = new PosixParser().parse(aOptions, args); ECommand eAction = null; boolean bGoodCmd = true; String cert = null; if (!cmd.hasOption("h")) { s_aLogger.error("No Host specified use -h to specify Host"); bGoodCmd = false; } if (!cmd.hasOption("u")) { s_aLogger.error("No Username specified use -u to specify username"); bGoodCmd = false; } if (!cmd.hasOption("p")) { s_aLogger.error("No Password specified use -p to specify password"); bGoodCmd = false; } if (!cmd.hasOption("c")) { s_aLogger.error("No Action specified please use -c parameter to specify command(" + ECommand.getAllAsString() + ")"); bGoodCmd = false; } else { final String sCommand = cmd.getOptionValue("c"); eAction = ECommand.getFromNameOrNull(sCommand); if (eAction == null) { s_aLogger.error("Illegal Action specified:" + sCommand + " allowed commands(" + ECommand.getAllAsString() + ")"); bGoodCmd = false; } else switch (eAction) { case ADDGROUP: if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } break; case DELGROUP: if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } break; case ADD: if (!cmd.hasOption("a")) { s_aLogger.error("No Accesspoint URL defined use -a to Specifify AP-URL"); bGoodCmd = false; } if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } if (!cmd.hasOption("d")) { s_aLogger.error("No DocumentType ID specified use -d to specify Document Type ID"); bGoodCmd = false; } if (!cmd.hasOption("r")) { s_aLogger.error("No Process ID specified use -r to specify Process ID"); bGoodCmd = false; } if (!cmd.hasOption("e")) { s_aLogger.error("No Certificate PEM file specified use -e to specify Certificate PEM file"); bGoodCmd = false; } else { cert = SimpleFileIO.readFileAsString(new File(cmd.getOptionValue('e')), CCharset.CHARSET_ISO_8859_1); } break; case DEL: if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } if (!cmd.hasOption("d")) { s_aLogger.error("No Document Type ID specified use -d to specify Document Type ID"); bGoodCmd = false; } } } if (!bGoodCmd) { final NonBlockingStringWriter aSW = new NonBlockingStringWriter(); new HelpFormatter().printHelp(new PrintWriter(aSW), HelpFormatter.DEFAULT_WIDTH, CGStringHelper.getClassLocalName(SMPClient.class), null, aOptions, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null); s_aLogger.info(aSW.getAsString()); System.exit(-3); } final SMPClient client = new SMPClient(new URI(cmd.getOptionValue('h')), cmd.getOptionValue('u'), cmd.getOptionValue('p'), cmd.getOptionValue('b'), cmd.getOptionValue('d'), cmd.getOptionValue('r'), cmd.getOptionValue('a'), cert); switch (eAction) { case ADDGROUP: client._createServiceGroup(); break; case DELGROUP: client._deleteServiceGroup(); break; case ADD: client._addDocument(); break; case DEL: client._deleteDocument(); break; case LIST: client._listDocuments(); break; default: throw new IllegalStateException(); } }
From source file:boa.BoaMain.java
protected static final void printHelp(final Options options, final String message) { if (message != null) System.err.println(message); final HelpFormatter help = new HelpFormatter(); final PrintWriter pw = new PrintWriter(System.out); help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, "The available options are:"); help.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD); help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, "\nPlease report issues at http://www.github.com/boalang/compiler"); pw.flush();/*from w w w.ja va 2s. c om*/ }
From source file:com.cloudera.csd.tools.MetricTools.java
/** * Writes usage message to 'stream'./*from www. j a v a2 s .co m*/ * * @param stream output stream. * @throws UnsupportedEncodingException */ public static void printUsageMessage(OutputStream stream) throws UnsupportedEncodingException { PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream, "UTF-8"))); try { String header = "Cloudera Manager Metric Tools"; String footer = ""; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, "metric tools", header, OPTIONS, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer, true); // auto-usage: whether to also show // the command line args on the usage line. } finally { writer.close(); } }
From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java
public void printHelp(PrintWriter stream, String usage, String header, String footer) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override/*from w w w.ja v a2s . co m*/ public int compare(Option opt1, Option opt2) { return (int) Math.signum(optionsOrder.get(opt1.getOpt()) - optionsOrder.get(opt2.getOpt())); } }); formatter.printHelp(stream, HelpFormatter.DEFAULT_WIDTH, usage, header, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer); }
From source file:com.cloudera.csd.tools.codahale.AbstractCodahaleFixtureGenerator.java
/** * Writes usage message to 'stream'./*from www . j a v a 2s .co m*/ * * @param stream output stream. * @throws UnsupportedEncodingException */ public static void printUsageMessage(OutputStream stream, Options options) throws UnsupportedEncodingException { PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream, "UTF-8"))); try { String header = "Mgmt Metric Schema Generator"; String footer = ""; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, "schema generator", header, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer, true); // auto-usage: whether to also show // the command line args on the usage line. } finally { writer.close(); } }
From source file:eu.scape_project.tool.toolwrapper.core.ToolWrapperCommandline.java
/** * Method used to print command-line syntax (usage) using * {@link HelpFormatter}/*w w w .java 2s . co m*/ */ public void printUsage() { HelpFormatter helpFormatter = new HelpFormatter(); PrintWriter systemErrPrintWriter = new PrintWriter( new OutputStreamWriter(System.err, Charset.defaultCharset()), true); helpFormatter.printHelp(systemErrPrintWriter, HelpFormatter.DEFAULT_WIDTH, "\"" + getClass().getSimpleName() + ".jar\"", null, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, Constants.SCAPE_COPYRIGHT_STATEMENT, true); }
From source file:de.weltraumschaf.groundzero.opt.commons.OptionsConfiguration.java
/** * Format the command line options./*w ww. ja va 2s. c o m*/ * * Useful to show help message. * * @param formatter Formatter to format with. * @param out Stream to print formatted output. */ public void format(final HelpFormatter formatter, final PrintStream out) { final PrintWriter writer = new PrintWriter(out); formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, CliOptions.EXECUTABLE, CliOptions.HEADER + CliOptions.DESCRIPTION, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "\n" + CliOptions.FOOTER, true); writer.flush(); }
From source file:hivemall.UDFWithOptions.java
protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException { String[] args = optionValue.split("\\s+"); Options opts = getOptions();/*from w w w . j av a 2 s . c o m*/ opts.addOption("help", false, "Show function help"); CommandLine cl = CommandLineUtils.parseOptions(args, opts); if (cl.hasOption("help")) { Description funcDesc = getClass().getAnnotation(Description.class); final String cmdLineSyntax; if (funcDesc == null) { cmdLineSyntax = getClass().getSimpleName(); } else { String funcName = funcDesc.name(); cmdLineSyntax = funcName == null ? getClass().getSimpleName() : funcDesc.value().replace("_FUNC_", funcDesc.name()); } StringWriter sw = new StringWriter(); sw.write('\n'); PrintWriter pw = new PrintWriter(sw); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true); pw.flush(); String helpMsg = sw.toString(); throw new UDFArgumentException(helpMsg); } return cl; }
From source file:hivemall.UDAFEvaluatorWithOptions.java
@Nonnull protected final CommandLine parseOptions(@Nonnull String optionValue) throws UDFArgumentException { String[] args = optionValue.split("\\s+"); Options opts = getOptions();/* w w w .j a va 2 s . co m*/ opts.addOption("help", false, "Show function help"); CommandLine cl = CommandLineUtils.parseOptions(args, opts); if (cl.hasOption("help")) { Description funcDesc = getClass().getAnnotation(Description.class); final String cmdLineSyntax; if (funcDesc == null) { cmdLineSyntax = getClass().getSimpleName(); } else { String funcName = funcDesc.name(); cmdLineSyntax = funcName == null ? getClass().getSimpleName() : funcDesc.value().replace("_FUNC_", funcDesc.name()); } StringWriter sw = new StringWriter(); sw.write('\n'); PrintWriter pw = new PrintWriter(sw); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true); pw.flush(); String helpMsg = sw.toString(); throw new UDFArgumentException(helpMsg); } return cl; }
From source file:com.teradata.tempto.runner.TemptoRunnerCommandLineParser.java
public void printHelpMessage(PrintWriter printWriter) { Options options = buildOptions();/*from w w w . j a va 2s . c om*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setOptionComparator(OPTION_BY_LONG_OPT_COMPARATOR); helpFormatter.printHelp(printWriter, 120, appName, null, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null); printWriter.flush(); }