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

The following examples show how to use org.apache.commons.cli.HelpFormatter#setWidth() . 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: ActiveOptionProcessor.java    From ofexport2 with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: CLI.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: ServerUtil.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: ServerUtil.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: CliFrontend.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example 6
Source File: ComingMain.java    From coming with MIT License 5 votes vote down vote up
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");

	}
 
Example 7
Source File: CliOptionsParser.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: CliFrontendParser.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 9
Source File: CliFrontendParser.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: ATSImportTool.java    From tez with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: CliFrontendParser.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 12
Source File: AbstractCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 13
Source File: CliFrontendParser.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: JumbuneAgent.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: ServerUtil.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public static void printCommandLineHelp(final String appName, final Options options) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    hf.printHelp(appName, options, true);
}
 
Example 16
Source File: AbstractBenchmark.java    From djl with Apache License 2.0 4 votes vote down vote up
private void printHelp(String msg, Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLeftPadding(1);
    formatter.setWidth(120);
    formatter.printHelp(msg, options);
}
 
Example 17
Source File: Main.java    From djl with Apache License 2.0 4 votes vote down vote up
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
    }
}
 
Example 18
Source File: CurrentStateCleanUp.java    From helix with Apache License 2.0 4 votes vote down vote up
public static void printUsage(Options cliOptions) {
  HelpFormatter helpFormatter = new HelpFormatter();
  helpFormatter.setWidth(1000);
  helpFormatter.printHelp("java " + CurrentStateCleanUp.class.getName(), cliOptions);
}
 
Example 19
Source File: ExampleProcess.java    From helix with Apache License 2.0 4 votes vote down vote up
public static void printUsage(Options cliOptions) {
  HelpFormatter helpFormatter = new HelpFormatter();
  helpFormatter.setWidth(1000);
  helpFormatter.printHelp("java " + ExampleProcess.class.getName(), cliOptions);
}
 
Example 20
Source File: ServerUtil.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public static void printCommandLineHelp(final String appName, final Options options) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    hf.printHelp(appName, options, true);
}