Example usage for org.apache.commons.cli HelpFormatter setLongOptPrefix

List of usage examples for org.apache.commons.cli HelpFormatter setLongOptPrefix

Introduction

In this page you can find the example usage for org.apache.commons.cli HelpFormatter setLongOptPrefix.

Prototype

public void setLongOptPrefix(String prefix) 

Source Link

Document

Sets the 'longOptPrefix'.

Usage

From source file:com.esri.geoevent.test.performance.OrchestratorMain.java

private static void printHelp(Options testHarnessOptions) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLongOptPrefix("-");
    formatter.setArgName("value");
    formatter.setWidth(100);// www .j  a  va 2 s  .c  o  m
    // do not sort the options in any order
    formatter.setOptionComparator(new Comparator<Option>() {
        @Override
        public int compare(Option o1, Option o2) {
            return 0;
        }
    });

    formatter.printHelp(ImplMessages.getMessage("ORCHESTRATOR_EXECUTOR_HELP_TITLE_MSG"), testHarnessOptions,
            true);
    System.out.println("");

}

From source file:com.esri.geoevent.test.performance.ConsumerMain.java

private static void printHelp(Options performerOptions) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLongOptPrefix("-");
    formatter.setArgName("value");
    formatter.setWidth(100);/*from   www  .  ja  v a  2 s  .c o  m*/
    // do not sort the options in any order
    formatter.setOptionComparator(new Comparator<Option>() {
        @Override
        public int compare(Option o1, Option o2) {
            return 0;
        }
    });

    formatter.printHelp(ImplMessages.getMessage("CONSUMER_EXECUTOR_HELP_TITLE_MSG"), performerOptions, true);
    System.out.println("");
}

From source file:com.esri.geoevent.test.performance.ProducerMain.java

private static void printHelp(Options performerOptions) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLongOptPrefix("-");
    formatter.setArgName("value");
    formatter.setWidth(100);/*from   w  ww  . j  av  a2  s  .  com*/
    // do not sort the options in any order
    formatter.setOptionComparator(new Comparator<Option>() {
        @Override
        public int compare(Option o1, Option o2) {
            return 0;
        }
    });

    formatter.printHelp(ImplMessages.getMessage("PRODUCER_EXECUTOR_HELP_TITLE_MSG"), performerOptions, true);
    System.out.println("");
}

From source file:com.aliyun.odps.ship.DShip.java

private static void help(String[] args) throws ParseException, IOException {

    OptionsBuilder.buildHelpOption(args);
    String cmd = DshipContext.INSTANCE.get(Constants.HELP_SUBCOMMAND);
    if (DshipContext.INSTANCE.get(Constants.HELP_SUBCOMMAND) == null) {
        cmd = "help";
    }// w  ww.  ja  va 2  s .  c  om

    HelpFormatter formatter = new HelpFormatter();
    formatter.setLongOptPrefix("-");
    CommandType type = CommandType.fromString(cmd);
    switch (type) {
    case upload:
        formatter.printHelp("tunnel upload [options] <path> <[project.]table[/partition]>\n"
                + "\tupload data from local file", OptionsBuilder.getUploadOptions());
        showHelp("upload.txt");
        break;
    case download:
        formatter.printHelp("tunnel download [options] <[project.]table[/partition]> <path>\n"
                + "\tdownload data to local file", OptionsBuilder.getDownloadOptions());
        showHelp("download.txt");
        break;
    case resume:
        formatter.printHelp("tunnel resume [session_id] [-force]\n" + "\tresume an upload session",
                OptionsBuilder.getResumeOptions());
        showHelp("resume.txt");
        break;
    case show:
        formatter.printHelp("tunnel show history [options]\n" + "\tshow session information",
                OptionsBuilder.getShowOptions());
        showHelp("show.txt");
        break;
    case purge:
        formatter.printHelp(
                "tunnel purge [n]\n" + "\tforce session history to be purged.([n] days before, default "
                        + Constants.DEFAULT_PURGE_NUMBER + " days)",
                OptionsBuilder.getPurgeOptions());
        showHelp("purge.txt");
        break;
    case help:
        showHelp("help.txt");
        break;
    default:
        break;
    }
}

From source file:com.eucalyptus.upgrade.TestHarness.java

@SuppressWarnings({ "static-access" })
private static void printHelp(Options opts) {
    try {//from   w  ww.ja  v a 2s .  com
        PrintWriter out = new PrintWriter(System.out);
        HelpFormatter help = new HelpFormatter();
        help.setArgName("TESTS");
        help.printHelp(out, LINE_BYTES, "java -jar test.jar", "Options controlling the test harness.", opts, 2,
                4, "", true);
        Multimap<Class, Method> testMethods = getTestMethods();
        help = new HelpFormatter();
        help.setLongOptPrefix("");
        help.setOptPrefix("");
        help.setSyntaxPrefix("");
        help.setLeftPadding(0);
        Options testOptions = new Options();
        for (Class c : testMethods.keySet()) {
            testOptions.addOption(
                    OptionBuilder.withDescription(getDescription(c)).withLongOpt(c.getSimpleName()).create());
            for (Method m : testMethods.get(c)) {
                testOptions.addOption(OptionBuilder.withDescription(getDescription(m))
                        .withLongOpt(c.getSimpleName() + "." + m.getName()).create());
            }
        }
        help.printHelp(out, LINE_BYTES, " ", "Tests:", testOptions, 0, 2, "", false);
        out.flush();
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
}

From source file:io.github.eternalbits.compactvd.CompactVD.java

private static void printHelp(Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setSyntaxPrefix("Usage: ");
    final String prefix = "--";
    String header = "\nTo reduce the size of dynamic disk images. Version " + version + "\n\n";
    String footer = ("\nOne of ^inline, ^copy or ^dump is required. For ^inline and ^dump"
            + " the default options are ^drop-unused ^keep-zeroed. For ^copy the default"
            + " is ^drop-unused and ^drop-zeroed is implied. Not applicable arguments" + " are ignored.\n")
                    .replace("^", prefix);
    formatter.setLongOptPrefix(" " + prefix);
    formatter.printHelp("java -jar " + jar, header, options, footer, true);
}

From source file:io.github.felsenhower.stine_calendar_bot.main.CallLevelWrapper.java

/**
 * Prints the help screen for the current Options instance and exits the
 * application/*from   w w  w .ja va 2s  .  c  om*/
 */
private void printHelp() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);
    formatter.setDescPadding(4);
    formatter.setLeftPadding(2);
    formatter.setLongOptSeparator("=");
    formatter.setLongOptPrefix(" --");
    formatter.setSyntaxPrefix(cliStrings.get("Usage"));
    formatter.printHelp(cliStrings.get("UsageTemplate", appInfo.get("Name")),
            cliStrings.get("HelpHeader", appInfo.get("Name"), appInfo.get("Version")), this.options,
            cliStrings.get("HelpFooter", cliStrings.get("Author"), cliStrings.get("License"),
                    appInfo.get("ProjectPage")),
            true);
    System.exit(0);
}

From source file:openlr.otk.options.UsageBuilder.java

/**
 * Prints the help for the tool arguments.
 * //from  w  w w.  ja v  a  2 s  .  c  o m
 * @param pw
 *            The writer to use
 * @param args
 *            The tool arguments
 */
private static void printArgumentDescriptions(final PrintWriter pw, final List<Argument<?>> args) {

    if (args.size() > 0) {

        pw.write(IOUtils.LINE_SEPARATOR);

        // We use the HelpFormatter to format the argument help for us
        // by providing fake options containing the arguments
        Options options = new Options();
        for (Argument<?> argument : args) {
            Option opt = new Option(null, argument.getName(), false, argument.getDescription());
            options.addOption(opt);
        }

        HelpFormatter formatter = new HelpFormatter();
        formatter.setLongOptPrefix("");

        formatter.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD,
                HelpFormatter.DEFAULT_DESC_PAD);
    }
}

From source file:org.apparatus_templi.Coordinator.java

/**
 * Parse all command line arguments. Any preferences read from the command like will be put into
 * the {@link Prefs} singleton./*from   w w w.ja va  2 s .c om*/
 * 
 * @param argv
 *            the command line arguments to be parsed
 */

private static void parseCommandLineOptions(String[] argv) {
    assert argv != null : "command line arguments should never be null";

    // Using apache commons cli to parse the command line options
    Options options = new Options();
    options.addOption("help", false, "Display this help message.");

    // the commons cli parser does not allow '.' within the option names, so we have to replace
    // the periods with underscores for now. When parsing the args later the underscores will be
    // converted back to proper dot notation
    for (String key : prefs.getDefPreferencesMap().keySet()) {
        String optName;
        if (key.contains(".")) {
            optName = key.replaceAll("\\.", "_");
        } else {
            optName = key;
        }

        options.addOption(OptionBuilder.withArgName(optName).hasArg()
                .withDescription(prefs.getPreferenceDesc(key)).create(optName));
    }

    CommandLineParser cliParser = new org.apache.commons.cli.PosixParser();
    try {
        CommandLine cmd = cliParser.parse(options, argv);
        if (cmd.hasOption("help")) {
            // show help message and exit
            HelpFormatter formatter = new HelpFormatter();
            formatter.setOptPrefix("--");
            formatter.setLongOptPrefix("--");

            formatter.printHelp(TAG, options);
            System.exit(0);
        }

        // Load the configuration file URI
        String configFile;
        if (cmd.hasOption(Prefs.Keys.configFile)) {
            configFile = cmd.getOptionValue(Prefs.Keys.configFile);
            if (configFile.startsWith("~" + File.separator)) {
                configFile = System.getProperty("user.home") + configFile.substring(1);
            }
        } else {
            configFile = prefs.getDefPreference(Prefs.Keys.configFile);
        }
        prefs.putPreference(Prefs.Keys.configFile, configFile);

        // Read in preferences from the config file
        prefs.readPreferences(configFile);

        // Read in preferences from the command line options
        for (Option opt : cmd.getOptions()) {
            // Apache CLI parser does not allow '.' within option names, so we have to convert
            // all '_' back to the '.' notation
            String key = opt.getArgName().replace("_", ".");
            String value = opt.getValue();
            prefs.putPreference(key, value);
        }
    } catch (ParseException e) {
        System.out.println("Error processing options: " + e.getMessage());
        new HelpFormatter().printHelp("Diff", options);
        Coordinator.exitWithReason("Error parsing command line options");
    }
}

From source file:org.codeseed.common.config.ext.CommandLineHelper.java

/**
 * Returns a property source from the supplied command line arguments.
 *
 * @param args//from ww w.  j av a  2s . com
 *            the arguments passed from the command line
 * @return a property source backed by the parsed command line arguments
 */
public PropertySource parse(String[] args) {
    // Construct the command line options
    final Options options = this.options.build();
    if (helpOption != null) {
        options.addOption(helpOption);
    }

    try {
        final CommandLine commandLine = parser.parse(options, args);
        if (helpOption != null && commandLine.hasOption(helpOption.getOpt())) {
            // Display the help
            HelpFormatter help = new HelpFormatter();
            help.setSyntaxPrefix(syntaxPrefix());
            help.setLongOptPrefix(" --");
            help.printHelp(err, terminalWidth, applicationName(), header(), options, 1, 1, footer(), true);
            return helpExit();
        } else {
            // Wrapped the parsed commands in a property source
            return new CommandLinePropertySource(commandLine);
        }
    } catch (ParseException e) {
        // Display the error and usage message
        HelpFormatter help = new HelpFormatter();
        help.printWrapped(err, terminalWidth, e.getMessage());
        help.printUsage(err, terminalWidth, applicationName(), options);
        throw usageExit(e);
    }
}