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

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

Introduction

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

Prototype

public void setWidth(int width) 

Source Link

Document

Sets the 'width'.

Usage

From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java

private static void displayHelp(Options options) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(135);
    hf.printHelp("proactive-users" + Tools.shellExtension(), "", options, "", true);
}

From source file:org.ow2.proactive.scheduler.util.console.SchedulerController.java

public void load(String[] args) {
    Options options = new Options();

    Option help = new Option("h", "help", false, "Display this help");
    help.setRequired(false);// w w  w . j  a  va 2s.c  om
    options.addOption(help);

    Option username = new Option("l", "login", true, "The username to join the Scheduler");
    username.setArgName("login");
    username.setArgs(1);
    username.setRequired(false);
    options.addOption(username);

    Option schedulerURL = new Option("u", "url", true,
            "The scheduler URL (default " + SCHEDULER_DEFAULT_URL + ")");
    schedulerURL.setArgName("schedulerURL");
    schedulerURL.setRequired(false);
    options.addOption(schedulerURL);

    Option keyfile = new Option("k", "key", true, "(Optional) The path to a private SSH key");
    keyfile.setArgName("sshkeyFilePath");
    keyfile.setArgs(1);
    keyfile.setRequired(false);
    options.addOption(keyfile);

    addCommandLineOptions(options);

    boolean displayHelp = false;

    try {
        String pwdMsg = null;

        Parser parser = new GnuParser();
        cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            displayHelp = true;
        } else {

            if (cmd.hasOption("env")) {
                model.setInitEnv(cmd.getOptionValue("env"));
            }
            String url;
            if (cmd.hasOption("url")) {
                url = cmd.getOptionValue("url");
            } else {
                url = SCHEDULER_DEFAULT_URL;
            }
            logger.info("Trying to connect Scheduler on " + url);
            auth = SchedulerConnection.join(url);
            logger.info("\t-> Connection established on " + url);

            logger.info(newline + "Connecting client to the Scheduler");

            if (cmd.hasOption("login")) {
                user = cmd.getOptionValue("login");
            }

            if (cmd.hasOption("credentials")) {
                if (cmd.getOptionValue("credentials") != null) {
                    System.setProperty(Credentials.credentialsPathProperty, cmd.getOptionValue("credentials"));
                }
                try {
                    this.credentials = Credentials.getCredentials();
                } catch (KeyException e) {
                    logger.error("Could not retreive credentials... Try to adjust the System property: "
                            + Credentials.credentialsPathProperty + " or use the -c option.");
                    throw e;
                }
            } else {
                ConsoleReader console = new ConsoleReader(System.in, new PrintWriter(System.out));
                if (cmd.hasOption("login")) {
                    pwdMsg = user + "'s password: ";
                } else {
                    user = console.readLine("login: ");
                    pwdMsg = "password: ";
                }

                //ask password to User
                try {
                    console.setDefaultPrompt(pwdMsg);
                    pwd = console.readLine('*');
                } catch (IOException ioe) {
                    logger.error("" + ioe);
                    logger.debug("", ioe);
                }

                PublicKey pubKey = null;
                try {
                    // first attempt at getting the pubkey : ask the scheduler
                    SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
                    pubKey = auth.getPublicKey();
                    logger.info("Retrieved public key from Scheduler at " + url);
                } catch (Exception e) {
                    try {
                        // second attempt : try default location
                        pubKey = Credentials.getPublicKey(Credentials.getPubKeyPath());
                        logger.info("Using public key at " + Credentials.getPubKeyPath());
                    } catch (Exception exc) {
                        logger.error(
                                "Could not find a public key. Contact the administrator of the Scheduler.");
                        logger.debug("", exc);
                        System.exit(7);
                    }
                }
                try {
                    if (cmd.hasOption("key")) {
                        byte[] keyfileContent = FileToBytesConverter
                                .convertFileToByteArray(new File(cmd.getOptionValue("key")));
                        this.credentials = Credentials.createCredentials(new CredData(CredData.parseLogin(user),
                                CredData.parseDomain(user), pwd, keyfileContent), pubKey);
                    } else {
                        this.credentials = Credentials.createCredentials(
                                new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd),
                                pubKey);
                    }
                } catch (FileNotFoundException fnfe) {
                    logger.error("SSH keyfile not found : '" + cmd.getOptionValue("key") + "'");
                    logger.debug("", fnfe);
                    System.exit(8);
                } catch (Exception e) {
                    logger.error("Could not create credentials... " + e);
                    throw e;
                }
            }

            //connect to the scheduler
            connect();
            //connect JMX service
            connectJMXClient();
            //start the command line or the interactive mode
            start();
        }
    } catch (MissingArgumentException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (MissingOptionException e) {
        logger.error("Missing option: " + e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (UnrecognizedOptionException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (AlreadySelectedException e) {
        logger.error(e.getClass().getSimpleName() + " : " + e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (ParseException e) {
        displayHelp = true;
    } catch (LoginException e) {
        logger.error(getMessages(e) + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(3);
    } catch (SchedulerException e) {
        logger.error(getMessages(e) + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(4);
    } catch (Exception e) {
        logger.error(getMessages(e) + "Shutdown the controller." + newline, e);
        logger.debug("", e);
        System.exit(5);
    }

    if (displayHelp) {
        logger.info("");
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(135);
        String note = newline + "NOTE : if no " + control
                + "command is specified, the controller will start in interactive mode.";
        hf.printHelp(getCommandName() + Tools.shellExtension(), "", options, note, true);
        System.exit(6);
    }

    // if execution reaches this point this means it must exit
    System.exit(0);
}

From source file:org.ow2.proactive.scheduler.util.SchedulerStarter.java

private static void displayHelp(Options options) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(120);
    hf.printHelp("proactive-server" + Tools.shellExtension(), options, true);
}

From source file:org.ppojo.HelpPrinter.java

public static void print(Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setSyntaxPrefix("");
    formatter.setOptionComparator(Comparator.instance);
    formatter.setWidth(140);
    formatter.printHelp("usage: papa-pojo -sources <sources folder> [options]", options);
}

From source file:org.psidnell.omnifocus.cli.ActiveOptionProcessor.java

@SuppressWarnings("unchecked")
public void printHelp() throws IOException {

    System.out.println(progName.toUpperCase());
    System.out.println();/*from ww w .  ja  v a 2s  .c o  m*/

    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);
}

From source file:org.rhq.server.metrics.migrator.DataMigratorRunner.java

private void configure(String args[]) throws Exception {
    options = new Options();

    options.addOption(cassandraUserOption);
    options.addOption(cassandraPasswordOption);
    options.addOption(cassandraHostsOption);
    options.addOption(cassandraPortOption);

    options.addOption(sqlUserOption);// w  w w  .  ja v a2s  . c om
    options.addOption(sqlPasswordOption);
    options.addOption(sqlHostOption);
    options.addOption(sqlPortOption);
    options.addOption(sqlDBOption);
    options.addOption(sqlServerTypeOption);
    options.addOption(sqlPostgresServerOption);
    options.addOption(sqlOracleServerOption);
    options.addOption(sqlConnectionUrlOption);

    options.addOption(disableRawOption);
    options.addOption(disable1HOption);
    options.addOption(disable6HOption);
    options.addOption(disable1DOption);
    options.addOption(deleteDataOption);
    options.addOption(estimateOnlyOption);
    options.addOption(deleteOnlyOption);
    options.addOption(experimentalExportOption);

    options.addOption(helpOption);
    options.addOption(debugLogOption);
    options.addOption(configFileOption);
    options.addOption(serverPropertiesFileOption);

    CommandLine commandLine;
    try {
        CommandLineParser parser = new PosixParser();
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("DataMigrationRunner", options);
        throw new Exception("Error parsing command line arguments");
    }

    if (commandLine.hasOption(helpOption.getLongOpt()) || commandLine.hasOption(helpOption.getOpt())) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("DataMigrationRunner", options);
        throw new HelpRequestedException();
    }

    if (commandLine.hasOption(debugLogOption.getLongOpt()) || commandLine.hasOption(debugLogOption.getOpt())) {
        DataMigratorRunner.setLogLevel(Level.DEBUG);
    }

    loadDefaultConfiguration();

    if (commandLine.hasOption(serverPropertiesFileOption.getLongOpt())) {
        log.debug("Server configuration file option enabled. Loading server configuration from file: "
                + serverPropertiesFileOption.getLongOpt());
        loadConfigurationFromServerPropertiesFile(
                commandLine.getOptionValue(serverPropertiesFileOption.getLongOpt()));
        log.debug(
                "Server configuration file from system properties will not be loaded even if set because of the manual override.");
    } else if (System.getProperty("rhq.server.properties-file") != null) {
        log.debug("Server configuration file system property detected. Loading the file: "
                + System.getProperty("rhq.server.properties-file"));
        loadConfigurationFromServerPropertiesFile(System.getProperty("rhq.server.properties-file"));
        log.debug("Server configuration file loaded based on system properties options.");
    }

    if (commandLine.hasOption(configFileOption.getLongOpt())) {
        loadConfigFile(commandLine.getOptionValue(configFileOption.getLongOpt()));
    }

    parseCassandraOptions(commandLine);
    parseSQLOptions(commandLine);
    parseMigrationOptions(commandLine);

    if (commandLine.hasOption(debugLogOption.getLongOpt()) || commandLine.hasOption(debugLogOption.getOpt())) {
        printOptions();
    }
}

From source file:org.sakuli.starter.helper.CmdPrintHelper.java

public static void printHelp(Options options) {
    printSakuliHeader();//from  w  ww . ja  v a  2s. c o m
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setWidth(80);
    helpFormatter.printHelp("sakuli [options]", options);
}

From source file:org.solenopsis.checkstyle.Main.java

/** Prints the usage information. **/
private static void printUsage() {
    final HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(HELP_WIDTH);
    formatter.printHelp(String.format("java %s [options] -c <config.xml> file...", Main.class.getName()),
            buildOptions());// w  w  w. ja v  a2s .c om
}

From source file:org.unitedid.yhsm.YubiHSMCmdLine.java

/**
 * Print usage information when running from command line.
 *
 * @param options the option definitions
 *///  w  w  w. jav  a  2s.c om
public static void printUsage(Options options) {
    HelpFormatter help = new HelpFormatter();
    help.setWidth(80);
    help.printHelp("[-D <device>] [OPTION]...", "", options, "");
}

From source file:org.voltdb.bulkloader.CLIDriver.java

/**
 * Display usage screen/*from  w  w w  .  j a v  a  2s  .  co  m*/
 */
public void usage() {
    HelpFormatter formatter = new HelpFormatter();
    if (this.helpData.width != null) {
        formatter.setWidth(this.helpData.width);
    }
    formatter.printHelp(this.helpData.syntax, this.helpData.header, this.options, this.helpData.footer, false);
}