List of usage examples for org.apache.commons.cli HelpFormatter getWidth
public int getWidth()
From source file:com.zimbra.perf.chart.ChartUtil.java
private static void usage(Options opts, String msg) { if (msg != null) System.err.println(msg);/* w w w .ja v a 2 s . c om*/ String invocation = "Usage: zmstat-chart -c <arg> -s <arg> -d <arg> [options]"; PrintWriter pw = new PrintWriter(System.err, true); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, formatter.getWidth(), invocation, null, opts, formatter.getLeftPadding(), formatter.getDescPadding(), null); pw.flush(); System.exit(1); }
From source file:com.zimbra.cs.util.SoapCLI.java
protected void usage(ParseException e, boolean showHiddenOptions) { if (e != null) { System.err.println("Error parsing command line arguments: " + e.getMessage()); }// w w w .j a va 2 s . co m Options opts = showHiddenOptions ? getAllOptions() : mOptions; PrintWriter pw = new PrintWriter(System.err, true); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, formatter.getWidth(), getCommandUsage(), null, opts, formatter.getLeftPadding(), formatter.getDescPadding(), null); pw.flush(); String trailer = getTrailer(); if (trailer != null && trailer.length() > 0) { System.err.println(); System.err.println(trailer); } }
From source file:org.apache.accumulo.server.util.Admin.java
public static void main(String[] args) { boolean everything; CommandLine cl = null;/*from w w w . j a va 2s. c o m*/ Options opts = new Options(); opts.addOption("u", true, "optional administrator user name"); opts.addOption("p", true, "optional administrator password"); opts.addOption("f", "force", false, "force the given server to stop by removing its lock"); opts.addOption("?", "help", false, "displays the help"); String user = null; byte[] pass = null; boolean force = false; try { cl = new BasicParser().parse(opts, args); if (cl.hasOption("?")) throw new ParseException("help requested"); args = cl.getArgs(); user = cl.hasOption("u") ? cl.getOptionValue("u") : "root"; pass = cl.hasOption("p") ? cl.getOptionValue("p").getBytes() : null; force = cl.hasOption("f"); if (!((cl.getArgs().length == 1 && (args[0].equalsIgnoreCase("stopMaster") || args[0].equalsIgnoreCase("stopAll"))) || (cl.getArgs().length == 2 && args[0].equalsIgnoreCase("stop")))) throw new ParseException("Incorrect arguments"); } catch (ParseException e) { // print to the log and to stderr if (cl == null || !cl.hasOption("?")) log.error(e, e); HelpFormatter h = new HelpFormatter(); StringWriter str = new StringWriter(); h.printHelp(new PrintWriter(str), h.getWidth(), Admin.class.getName() + " stopMaster | stopAll | stop <tserver>", null, opts, h.getLeftPadding(), h.getDescPadding(), null, true); if (cl != null && cl.hasOption("?")) log.info(str.toString()); else log.error(str.toString()); h.printHelp(new PrintWriter(System.err), h.getWidth(), Admin.class.getName() + " stopMaster | stopAll | stop <tserver>", null, opts, h.getLeftPadding(), h.getDescPadding(), null, true); System.exit(3); } try { AuthInfo creds; if (args[0].equalsIgnoreCase("stop")) { stopTabletServer(args[1], force); } else { if (!cl.hasOption("u") && !cl.hasOption("p")) { creds = SecurityConstants.getSystemCredentials(); } else { if (pass == null) { try { pass = new ConsoleReader().readLine("Enter current password for '" + user + "': ", '*') .getBytes(); } catch (IOException ioe) { log.error("Password not specified and unable to prompt: " + ioe); System.exit(4); } } creds = new AuthInfo(user, ByteBuffer.wrap(pass), HdfsZooInstance.getInstance().getInstanceID()); } everything = args[0].equalsIgnoreCase("stopAll"); stopServer(creds, everything); } } catch (AccumuloException e) { log.error(e); System.exit(1); } catch (AccumuloSecurityException e) { log.error(e); System.exit(2); } }
From source file:org.apache.carbondata.tool.CarbonCli.java
private static void collectHelpInfo(Options options) { HelpFormatter formatter = new HelpFormatter(); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); formatter.printHelp(printWriter, formatter.getWidth(), "CarbonCli", null, options, formatter.getLeftPadding(), formatter.getDescPadding(), null, false); printWriter.flush();//from www.ja va2 s . co m outPuts.add(stringWriter.toString()); }
From source file:org.apache.hadoop.hive.llap.cli.LlapOptionsProcessor.java
private void printUsage() { HelpFormatter hf = new HelpFormatter(); try {/* w ww . j a va 2 s . com*/ int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); // Ignore potentially incorrect values hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("llap", options); }
From source file:org.apache.hadoop.hive.llap.cli.LlapStatusOptionsProcessor.java
public static void printUsage() { HelpFormatter hf = new HelpFormatter(); try {// w ww. jav a 2s .com int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); // Ignore potentially incorrect values hf.setWidth(width); } catch (Throwable t) { // Ignore } LlapStatusOptionsProcessor optionsProcessor = new LlapStatusOptionsProcessor(); hf.printHelp(LLAPSTATUS_CONSTANT, optionsProcessor.options); }
From source file:org.apache.hadoop.hive.llap.cli.service.LlapServiceCommandLine.java
private static void printUsage() { HelpFormatter hf = new HelpFormatter(); try {/* ww w.j av a 2s . c o m*/ int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("llap", OPTIONS); }
From source file:org.apache.hadoop.hive.llap.cli.status.LlapStatusServiceCommandLine.java
private static void printUsage() { HelpFormatter hf = new HelpFormatter(); try {//ww w. j a v a 2 s. c om int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("llapstatus", OPTIONS); }
From source file:org.apache.hadoop.hive.metastore.tools.metatool.HiveMetaToolCommandLine.java
private static void printUsage() { HelpFormatter hf = new HelpFormatter(); try {/*from w w w . ja v a2 s . co m*/ int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("metatool", OPTIONS); }
From source file:org.apache.nifi.toolkit.cli.impl.command.AbstractCommand.java
@Override public void printUsage(String errorMessage) { output.println();// w w w. j ava 2 s . co m if (errorMessage != null) { output.println("ERROR: " + errorMessage); output.println(); } final PrintWriter printWriter = new PrintWriter(output); final int width = 80; final HelpFormatter hf = new HelpFormatter(); hf.setWidth(width); hf.printWrapped(printWriter, width, getDescription()); hf.printWrapped(printWriter, width, ""); if (isReferencable()) { hf.printWrapped(printWriter, width, "PRODUCES BACK-REFERENCES"); hf.printWrapped(printWriter, width, ""); } hf.printHelp(printWriter, hf.getWidth(), getName(), null, getOptions(), hf.getLeftPadding(), hf.getDescPadding(), null, false); printWriter.println(); printWriter.flush(); }