List of usage examples for org.apache.commons.cli2.util HelpFormatter setDivider
public void setDivider(String divider)
From source file:it.jnrpe.server.JNRPEServer.java
/** * Prints the JNRPE Server usage and, eventually, the error about the last * invocation./*from www.j a v a 2 s . c o m*/ * * @param e * The last error. Can be null. */ @SuppressWarnings("unchecked") private static void printUsage(final Exception e) { printVersion(); if (e != null) { System.out.println(e.getMessage() + "\n"); } HelpFormatter hf = new HelpFormatter(); StringBuilder sbDivider = new StringBuilder("="); while (sbDivider.length() < hf.getPageWidth()) { sbDivider.append("="); } // DISPLAY SETTING hf.getDisplaySettings().clear(); hf.getDisplaySettings().add(DisplaySetting.DISPLAY_GROUP_EXPANDED); hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN); // USAGE SETTING hf.getFullUsageSettings().clear(); hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT); hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED); hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN); hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_EXPANDED); hf.setDivider(sbDivider.toString()); hf.setGroup(configureCommandLine()); hf.print(); System.exit(0); }
From source file:it.jnrpe.client.JNRPEClient.java
/** * Prints usage instrunctions and, eventually, an error message about the * latest execution./*w w w. java 2s. com*/ * * @param e * The exception error */ @SuppressWarnings("unchecked") private static void printUsage(final Exception e) { printVersion(); StringBuilder sbDivider = new StringBuilder("="); if (e != null) { System.out.println(e.getMessage() + "\n"); } HelpFormatter hf = new HelpFormatter(); while (sbDivider.length() < hf.getPageWidth()) { sbDivider.append('='); } // DISPLAY SETTING Set displaySettings = hf.getDisplaySettings(); displaySettings.clear(); displaySettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED); displaySettings.add(DisplaySetting.DISPLAY_PARENT_CHILDREN); // USAGE SETTING Set usageSettings = hf.getFullUsageSettings(); usageSettings.clear(); usageSettings.add(DisplaySetting.DISPLAY_PARENT_ARGUMENT); usageSettings.add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED); usageSettings.add(DisplaySetting.DISPLAY_PARENT_CHILDREN); usageSettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED); hf.setDivider(sbDivider.toString()); hf.setGroup(configureCommandLine()); hf.print(); }
From source file:br.edu.ifpb.pos.command.CommandExecute.java
@Override public void run() throws ResourceException { System.out.println(""); if (line.hasOption("--help")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setGroup(options); helpFormatter.setDivider(" "); helpFormatter.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_OUTER); helpFormatter.print();// w w w . j a v a 2s .co m } if (line.hasOption("--insert")) { Representation representation = new StringRepresentation((CharSequence) line.getValue("--insert"), MediaType.APPLICATION_JSON); ClientResource clientResource; if (line.getValue("--type").equals(TYPE_PERSON)) { clientResource = new ClientResource(URL + "/person"); } else { clientResource = new ClientResource(URL + "/user"); } try { clientResource.post(representation).write(System.out); System.out.println(""); } catch (IOException ex) { Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex); } } if (line.hasOption("--update")) { String entity = (String) line.getValue("--update"); Representation representation = new StringRepresentation(entity, MediaType.APPLICATION_JSON); ClientResource clientResource; Gson gson = new Gson(); if (line.getValue("--type").equals(TYPE_PERSON)) { Key key = gson.fromJson(entity, Key.class); clientResource = new ClientResource(URL + "/person/" + key.getKey()); } else { Key key = gson.fromJson(entity, Key.class); clientResource = new ClientResource(URL + "/user/" + key.getKey()); } try { clientResource.put(representation).write(System.out); System.out.println(""); } catch (IOException ex) { Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex); } } if (line.hasOption("--delete")) { ClientResource clientResource; String key = getKey(line.getValue("--delete").toString()); if (line.getValue("--type").equals(TYPE_PERSON)) { clientResource = new ClientResource(URL + "/person/" + key); } else { clientResource = new ClientResource(URL + "/user/" + key); } try { clientResource.delete().write(System.out); System.out.println(""); } catch (IOException ex) { Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex); } } if (line.hasOption("--select")) { ClientResource clientResource; String key = getKey(line.getValue("--select").toString()); if (line.getValue("--type").equals(TYPE_PERSON)) { clientResource = new ClientResource(URL + "/person/" + key); } else { clientResource = new ClientResource(URL + "/user/" + key); } Representation representation = clientResource.get(); try { System.out.println(representation.getText()); } catch (IOException ex) { Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:it.geosolutions.utils.db.BaseArgumentsManager.java
private void finishOptInitialization() { // ///////////////////////////////////////////////////////////////////// ///*from w w w. j a v a 2 s . c o m*/ // Help Formatter // // ///////////////////////////////////////////////////////////////////// final HelpFormatter cmdHlp = new HelpFormatter("| ", " ", " |", 75); cmdHlp.setShellCommand(getToolName()); cmdHlp.setHeader("Help"); cmdHlp.setFooter(new StringBuffer(getToolName() + " - GeoSolutions S.a.s (C) 2009-2013 - v ") .append(getVersion()).toString()); cmdHlp.setDivider("|-------------------------------------------------------------------------|"); // ///////////////////////////////////////////////////////////////////// // // Close Parser // // ///////////////////////////////////////////////////////////////////// optionsGroup = new GroupImpl(cmdOpts, "Options", "All the options", 1, cmdOpts.size()); cmdParser.setGroup(optionsGroup); cmdParser.setHelpOption(helpOpt); cmdParser.setHelpFormatter(cmdHlp); }
From source file:it.jnrpe.plugins.PluginProxy.java
/** * Prints the help related to the plugin to a specified output. * //from ww w . j av a2s .c om * @param out * the writer where the help should be written */ public void printHelp(final PrintWriter out) { HelpFormatter hf = new HelpFormatter(); StringBuilder sbDivider = new StringBuilder("="); while (sbDivider.length() < hf.getPageWidth()) { sbDivider.append('='); } out.println(sbDivider.toString()); out.println("PLUGIN NAME : " + proxyedPluginDefinition.getName()); if (description != null && description.trim().length() != 0) { out.println(sbDivider.toString()); out.println("Description : "); out.println(); out.println(description); } hf.setGroup(mainOptionsGroup); // hf.setHeader(m_pluginDef.getName()); hf.setDivider(sbDivider.toString()); hf.setPrintWriter(out); hf.print(); // hf.printHelp(m_pluginDef.getName(), m_Options); }
From source file:org.geotools.utils.progress.BaseArgumentsManager.java
protected void finishInitialization() { // ///////////////////////////////////////////////////////////////////// //// ww w . j ava2 s . com // Help Formatter // // ///////////////////////////////////////////////////////////////////// final HelpFormatter cmdHlp = new HelpFormatter("| ", " ", " |", 75); cmdHlp.setShellCommand(getToolName()); cmdHlp.setHeader("Help"); cmdHlp.setFooter(new StringBuffer(getToolName() + " - GeoSolutions S.a.s (C) 2006 - v ") .append(getVersion()).toString()); cmdHlp.setDivider("|-------------------------------------------------------------------------|"); // ///////////////////////////////////////////////////////////////////// // // Close Parser // // ///////////////////////////////////////////////////////////////////// optionsGroup = new GroupImpl(cmdOpts, "Options", "All the options", 1, cmdOpts.size()); cmdParser.setGroup(optionsGroup); cmdParser.setHelpOption(helpOpt); cmdParser.setHelpFormatter(cmdHlp); }