下面列出了org.apache.commons.cli.HelpFormatter#setWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
CommandLineParser parser) {
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp(appName, options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp(appName, options, true);
}
return commandLine;
}
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
CommandLineParser parser) {
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp(appName, options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp(appName, options, true);
}
return commandLine;
}
/**
* Print help and exit the program
* @param options
*/
private static void printHelpAndExit() {
final Options options = OptionsHelper.buildOptions();
final String allActions = CLIAction.ALL_ACTIONS
.stream().collect(Collectors.joining(", ", "[", "]"));
final String allBuilder = TupleBuilderFactory.ALL_BUILDER
.stream().collect(Collectors.joining(", ", "[", "]"));
final String header = "BBoxDB command line interace (CLI)\n\n"
+ "Available actions are: " + allActions + "\n"
+ "Supported import formats: " + allBuilder + "\n\n";
final String footer = "\nPlease report issues at https://github.com/jnidzwetzki/bboxdb/issues\n";
final HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp("CLI", header, options, footer);
System.exit(-1);
}
@SuppressWarnings("unchecked")
public void printHelp() throws IOException {
System.out.println (progName.toUpperCase());
System.out.println();
try (
InputStream in = this.getClass().getResourceAsStream("/version.properties")) {
Properties p = new Properties();
p.load(in);
System.out.println ("Version: " + p.getProperty("version"));
System.out.println ("Build Date: " + p.getProperty("date"));
}
System.out.println();
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(200);
// Output in the order I specify
formatter.setOptionComparator((x, y) -> ((ActiveOption<P>) x).getOrder() - ((ActiveOption<P>) y).getOrder());
formatter.printHelp(progName, options);
}
private static void displayOptions(Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.setOptionComparator(null);
formatter.setWidth(80);
formatter.printHelp("java -jar <jumbune jar file>.jar", options, true);
exitVM(0);
}
public static void printHelpForRun(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
System.out.println("\nAction \"run\" compiles and runs a program.");
System.out.println("\n Syntax: run [OPTIONS] <jar-file> <arguments>");
formatter.setSyntaxPrefix(" \"run\" action options:");
formatter.printHelp(" ", getRunOptionsWithoutDeprecatedOptions(new Options()));
printCustomCliOptions(customCommandLines, formatter, true);
System.out.println();
}
@Override
public void printUsage(String errorMessage) {
output.println();
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();
}
public static void printHelpForStop(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
System.out.println("\nAction \"stop\" stops a running program (streaming jobs only).");
System.out.println("\n Syntax: stop [OPTIONS] <Job ID>");
formatter.setSyntaxPrefix(" \"stop\" action options:");
formatter.printHelp(" ", getStopOptionsWithoutDeprecatedOptions(new Options()));
printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
static void printHelp(Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(240);
String help = LINE_SEPARATOR
+ "java -cp tez-history-parser-x.y.z-jar-with-dependencies.jar org.apache.tez.history.ATSImportTool"
+ LINE_SEPARATOR
+ "OR"
+ LINE_SEPARATOR
+ "HADOOP_CLASSPATH=$TEZ_HOME/*:$TEZ_HOME/lib/*:$HADOOP_CLASSPATH hadoop jar "
+ "tez-history-parser-x.y.z.jar " + ATSImportTool.class.getName()
+ LINE_SEPARATOR;
formatter.printHelp(240, help, "Options", options, "", true);
}
private void printHelpForRun() {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
System.out.println("\nAction \"run\" compiles and runs a program.");
System.out.println("\n Syntax: run [OPTIONS] <jar-file> <arguments>");
formatter.setSyntaxPrefix(" \"run\" action arguments:");
formatter.printHelp(" ", getRunOptionsWithoutDeprecatedOptions(new Options()));
}
public static void printHelpForList(Collection<CustomCommandLine> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
System.out.println("\nAction \"list\" lists running and scheduled programs.");
System.out.println("\n Syntax: list [OPTIONS]");
formatter.setSyntaxPrefix(" \"list\" action options:");
formatter.printHelp(" ", getListOptionsWithoutDeprecatedOptions(new Options()));
printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
public static void printHelpForSavepoint(Collection<CustomCommandLine> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
System.out.println("\nAction \"savepoint\" triggers savepoints for a running job or disposes existing ones.");
System.out.println("\n Syntax: savepoint [OPTIONS] <Job ID> [<target directory>]");
formatter.setSyntaxPrefix(" \"savepoint\" action options:");
formatter.printHelp(" ", getSavepointOptionsWithoutDeprecatedOptions(new Options()));
printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
public static void printHelpEmbeddedModeClient() {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
System.out.println("\nMode \"embedded\" submits Flink jobs from the local machine.");
System.out.println("\n Syntax: embedded [OPTIONS]");
formatter.setSyntaxPrefix(" \"embedded\" mode options:");
formatter.printHelp(" ", EMBEDDED_MODE_CLIENT_OPTIONS);
System.out.println();
}
private static void help() {
HelpFormatter formater = new HelpFormatter();
formater.setWidth(500);
formater.printHelp("Main", options);
logm.info("More options and default values at 'config-coming.properties' file");
}
public static void printCommandLineHelp(final String appName, final Options options) {
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
hf.printHelp(appName, options, true);
}
public static void printUsage(Options cliOptions) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.setWidth(1000);
helpFormatter.printHelp("java " + ExampleProcess.class.getName(), cliOptions);
}
public static void printCommandLineHelp(final String appName, final Options options) {
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
hf.printHelp(appName, options, true);
}
private void printHelp(String msg, Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(1);
formatter.setWidth(120);
formatter.printHelp(msg, options);
}
public static void main(String[] args) {
Options options = Config.getOptions();
try {
DefaultParser cmdParser = new DefaultParser();
CommandLine cmd = cmdParser.parse(options, args, null, false);
Config config = new Config(cmd);
String output = config.getOutput();
String packageName = config.getPackageName();
String library = config.getLibrary();
String[] headerFiles = config.getHeaderFiles();
String mappingFile = config.getMappingFile();
Path dir = Paths.get(output);
Files.createDirectories(dir);
Properties mapping = new Properties();
if (mappingFile != null) {
Path file = Paths.get(mappingFile);
if (Files.notExists(file)) {
logger.error("mapping file does not exists: {}", mappingFile);
System.exit(-1); // NOPMD
}
try (InputStream in = Files.newInputStream(file)) {
mapping.load(in);
}
}
JnaParser jnaParser = new JnaParser();
Map<String, TypeDefine> typedefMap = jnaParser.getTypedefMap();
Map<String, List<TypeDefine>> structMap = jnaParser.getStructMap();
JnaGenerator generator =
new JnaGenerator(library, packageName, typedefMap, structMap.keySet(), mapping);
generator.init(output);
for (String headerFile : headerFiles) {
jnaParser.parse(headerFile);
}
generator.writeNativeSize();
generator.writeStructure(structMap);
generator.writeLibrary(jnaParser.getFunctions(), jnaParser.getEnumMap());
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(1);
formatter.setWidth(120);
formatter.printHelp(e.getMessage(), options);
System.exit(-1); // NOPMD
} catch (Throwable t) {
logger.error("", t);
System.exit(-1); // NOPMD
}
}
public static void printUsage(Options cliOptions) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.setWidth(1000);
helpFormatter.printHelp("java " + CurrentStateCleanUp.class.getName(), cliOptions);
}