Java 类org.apache.commons.cli2.util.HelpFormatter 实例源码
项目:jnrpe
文件:PluginProxy.java
/**
* Prints the help related to the plugin to a specified output.
*
* @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);
}
项目:jnrpe
文件:PluginCommand.java
public String getCommandLine() {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Group g = getCommandLineGroup();
HelpFormatter hf = new HelpFormatter(null, null, null, getConsole().getTerminal().getWidth());
hf.setGroup(g);
hf.setPrintWriter(new PrintWriter(new OutputStreamWriter(bout, charset)));
hf.printUsage();
String usage = new String(bout.toByteArray(), charset);
String[] lines = usage.split("\\n");
StringBuilder res = new StringBuilder();
for (int i = 1; i < lines.length; i++) {
res.append(lines[i]);
}
return res.toString();
}
项目:jnrpe
文件:PluginCommand.java
public void printHelp() throws IOException {
Group g = getCommandLineGroup();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
HelpFormatter hf = new HelpFormatter(" ", null, null, getConsole().getTerminal().getWidth());
hf.setGroup(g);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(bout, charset));
hf.setPrintWriter(pw);
hf.printHelp();
pw.flush();
// getConsole().println("\u001B[1mCommand Line:\u001B[0m ");
getConsole().println(highlight("Command Line: "));
getConsole().println(" " + getName() + " " + getCommandLine());
getConsole().println(highlight("Usage:"));
getConsole().println(new String(bout.toByteArray(), charset));
}
项目:jnrpe
文件:JNRPEServer.java
/**
* Parses the command line.
*
* @param vsArgs
* The command line
* @return The parsed command line
*/
private static CommandLine parseCommandLine(final String[] vsArgs) {
try {
Group opts = configureCommandLine();
// configure a HelpFormatter
HelpFormatter hf = new HelpFormatter();
// configure a parser
Parser p = new Parser();
p.setGroup(opts);
p.setHelpFormatter(hf);
// p.setHelpTrigger("--help");
return p.parse(vsArgs);
} catch (OptionException oe) {
printUsage(oe);
} catch (Exception e) {
e.printStackTrace();
// Should never happen...
}
return null;
}
项目:Chi-FRBCS-BigDataCS
文件:CommandLineUtil.java
/**
* Print the options supported by {@code GenericOptionsParser}.
* In addition to the options supported by the job, passed in as the
* group parameter.
*
* @param group job-specific command-line options.
*/
public static void printHelpWithGenericOptions(Group group) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setFooter("Specify HDFS directories while running on hadoop; else specify local file system directories");
formatter.print();
}
项目:Chi-FRBCS-BigDataCS
文件:CommandLineUtil.java
public static void printHelpWithGenericOptions(Group group, OptionException oe) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setException(oe);
formatter.print();
}
项目:Chi-FRBCS-BigData-Ave
文件:CommandLineUtil.java
/**
* Print the options supported by {@code GenericOptionsParser}.
* In addition to the options supported by the job, passed in as the
* group parameter.
*
* @param group job-specific command-line options.
*/
public static void printHelpWithGenericOptions(Group group) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setFooter("Specify HDFS directories while running on hadoop; else specify local file system directories");
formatter.print();
}
项目:Chi-FRBCS-BigData-Ave
文件:CommandLineUtil.java
public static void printHelpWithGenericOptions(Group group, OptionException oe) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setException(oe);
formatter.print();
}
项目:Chi-FRBCS-BigData-Max
文件:CommandLineUtil.java
/**
* Print the options supported by {@code GenericOptionsParser}.
* In addition to the options supported by the job, passed in as the
* group parameter.
*
* @param group job-specific command-line options.
*/
public static void printHelpWithGenericOptions(Group group) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setFooter("Specify HDFS directories while running on hadoop; else specify local file system directories");
formatter.print();
}
项目:Chi-FRBCS-BigData-Max
文件:CommandLineUtil.java
public static void printHelpWithGenericOptions(Group group, OptionException oe) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setException(oe);
formatter.print();
}
项目:jnrpe
文件:JNRPEClient.java
/**
* Prints usage instrunctions and, eventually, an error message about the
* latest execution.
*
* @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();
}
项目:jnrpe
文件:JNRPEServer.java
/**
* Prints the JNRPE Server usage and, eventually, the error about the last
* invocation.
*
* @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);
}
项目:Chi-FRBCS-BigDataCS
文件:CommandLineUtil.java
public static void printHelp(Group group) {
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.print();
}
项目:Chi-FRBCS-BigData-Ave
文件:CommandLineUtil.java
public static void printHelp(Group group) {
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.print();
}
项目:Chi-FRBCS-BigData-Max
文件:CommandLineUtil.java
public static void printHelp(Group group) {
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.print();
}