Java Code Examples for org.apache.commons.cli.HelpFormatter#printUsage()

The following examples show how to use org.apache.commons.cli.HelpFormatter#printUsage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
public static void showUsage(HelpFormatter format, PrintWriter err, String name, Command command) {
  Options options = mergeOptions(OPTIONS, command.getOptions());
  String[] usage = command.getUsageDescription();

  String ustr = name + " [option...]";
  if (usage != null && usage.length >= 1) {
    ustr = ustr + " " + usage[0];
  }

  format.printWrapped(err, WIDTH, name + ":\n" + command.getCommandDescription());
  format.printUsage(err, WIDTH, ustr);
  format.printWrapped(err, WIDTH, LEFT_PAD, "where option is one of:");
  format.printOptions(err, WIDTH, options, LEFT_PAD, DESC_PAD);

  if (usage != null && usage.length >= 2) {
    for (int i = 1; i < usage.length; ++i) {
      format.printWrapped(err, WIDTH, LEFT_PAD, usage[i]);
    }
  }
}
 
Example 2
Source File: Main.java    From parquet-tools with Apache License 2.0 6 votes vote down vote up
public static void showUsage(HelpFormatter format, PrintWriter err, String name, Command command) {
  Options options = mergeOptions(OPTIONS, command.getOptions());
  String[] usage = command.getUsageDescription();

  String ustr = name + " [option...]";
  if (usage != null && usage.length >= 1) {
    ustr = ustr + " " + usage[0];
  }
    
  format.printUsage(err, WIDTH, ustr);
  format.printWrapped(err, WIDTH, LEFT_PAD, "where option is one of:");
  format.printOptions(err, WIDTH, options, LEFT_PAD, DESC_PAD);

  if (usage != null && usage.length >= 2) {
    for (int i = 1; i < usage.length; ++i) {
      format.printWrapped(err, WIDTH, LEFT_PAD, usage[i]);
    }
  }
}
 
Example 3
Source File: HopServer.java    From hop with Apache License 2.0 5 votes vote down vote up
private static String getOptionsHelpForUsage() {
  HelpFormatter formatter = new HelpFormatter();
  StringWriter stringWriter = new StringWriter();
  PrintWriter printWriter = new PrintWriter( stringWriter );
  formatter.printUsage( printWriter, 999, "", options );
  return stripOff( stringWriter.toString(), "usage: " ); // Strip off the "usage:" so it can be localized
}
 
Example 4
Source File: MLPlanCLI.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void printUsage(final Options options) {
	final HelpFormatter formatter = new HelpFormatter();
	final String syntax = "mlplan";
	final PrintWriter pw = new PrintWriter(System.out);
	formatter.printUsage(pw, 400, syntax, options);
	pw.println("use -h or --help for help");
	pw.flush();
}
 
Example 5
Source File: CLITools.java    From ECTester with MIT License 5 votes vote down vote up
private static void usage(HelpFormatter help, PrintWriter pw, CommandLineParser cli, Options opts) {
    StringWriter sw = new StringWriter();
    PrintWriter upw = new PrintWriter(sw);
    help.printUsage(upw, HelpFormatter.DEFAULT_WIDTH, "", opts);
    if (cli instanceof TreeParser) {
        upw.print(" ");
        TreeParser tp = (TreeParser) cli;
        String[] keys = tp.getParsers().keySet().toArray(new String[tp.getParsers().size()]);
        if (keys.length > 0 && !tp.isRequired()) {
            upw.print("[ ");
        }

        for (int i = 0; i < keys.length; ++i) {
            String key = keys[i];
            ParserOptions value = tp.getParsers().get(key);
            upw.print("(" + key);
            usage(help, upw, value.getParser(), value.getOptions());
            upw.print(")");
            if (i != keys.length - 1) {
                upw.print(" | ");
            }
        }

        if (keys.length > 0 && !tp.isRequired()) {
            upw.print(" ]");
        }

        Argument[] args = tp.getArgs().toArray(new Argument[tp.getArgs().size()]);
        if (args.length > 0) {
            String[] argss = new String[tp.getArgs().size()];
            for (int i = 0; i < args.length; ++i) {
                Argument arg = args[i];
                argss[i] = arg.isRequired() ? "<" + arg.getName() + ">" : "[" + arg.getName() + "]";
            }
            upw.print(" " + String.join(" ", argss));
        }
    }
    pw.println(sw.toString().replaceAll("usage:( )?", "").replace("\n", ""));
}
 
Example 6
Source File: Carte.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static String getOptionsHelpForUsage() {
  HelpFormatter formatter = new HelpFormatter();
  StringWriter stringWriter = new StringWriter();
  PrintWriter printWriter = new PrintWriter( stringWriter );
  formatter.printUsage( printWriter, 999, "", options );
  return stripOff( stringWriter.toString(), "usage: " ); // Strip off the "usage:" so it can be localized
}
 
Example 7
Source File: SingleTaskRunnerMainOptions.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
private void printUsage(final Options options) {
  final HelpFormatter formatter = new HelpFormatter();
  formatter.printUsage(this.writer, CHARACTERS_PER_LINE, SingleTaskRunnerMain.class.getSimpleName(), options);
}
 
Example 8
Source File: CliUtil.java    From termsuite-core with Apache License 2.0 3 votes vote down vote up
/**
 * Prints the command line usage to the std error output
 * 
 * @param e
 *            The error that raised the help message
 * @param cmdLine
 *            The command line usage
 * @param options
 *            The options expected
 */
public static void printUsage(ParseException e, String cmdLine,
		Options options) {
	System.err.println(e.getMessage());
	// automatically generate the help statement
	HelpFormatter formatter = new HelpFormatter();
	PrintWriter pw = new PrintWriter(System.err);
	formatter.printUsage(pw, cmdLine.length() + 7, cmdLine, options);
	pw.flush();
}