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.javaan.JavaanCli.java

private void printCommandUsage(Command command, Options options) {
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setWidth(MAX_WIDTH);
    helpFormatter.printHelp(command.getHelpCommandLine() + "\n", command.getDescription(), options, "");
}

From source file:org.jkiss.dbeaver.core.application.DBeaverApplication.java

private boolean handleCommandLine(String instanceLoc) {
    CommandLine commandLine = getCommandLine();
    if (commandLine == null) {
        return false;
    }/*  ww  w  .java  2s .  c  om*/
    if (commandLine.hasOption(DBeaverCommandLine.PARAM_HELP)) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.setWidth(120);
        helpFormatter.setOptionComparator(new Comparator<Option>() {
            @Override
            public int compare(Option o1, Option o2) {
                return 0;
            }
        });
        helpFormatter.printHelp("dbeaver", DBeaverCore.getProductTitle(), DBeaverCommandLine.ALL_OPTIONS,
                "(C) 2016 JKISS", true);
        return true;
    }

    try {
        IInstanceController controller = InstanceClient.createClient(instanceLoc);
        if (controller == null) {
            return false;
        }

        return executeCommandLineCommands(commandLine, controller);
    } catch (RemoteException e) {
        log.error("Error calling remote server", e);
        return true;
    } catch (Throwable e) {
        log.error("Internal error while calling remote server", e);
        return false;
    }
}

From source file:org.kawanfw.sql.WebServer.java

/**
 * Prints usage/*from  w  w  w .jav  a  2 s  .co m*/
 * 
 * @param options
 *            the CLI Options
 */
private static void printUsage(Options options) {
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(400);

    String fromAceqlServerScript = System.getProperty("from.aceql-server.script");

    String help = null;

    if (fromAceqlServerScript != null && fromAceqlServerScript.equals("true")) {
        help = "aceql-server -start -host <hostname> -port <port> -properties <file>" + CR_LF + "or " + CR_LF
                + "-stop -port <port> ";
    } else {
        help = "java org.kawanfw.sql.WebServer -start -host <hostname> -port <port> -properties <file>" + CR_LF
                + "or " + CR_LF + "-stop -port <port> ";
    }

    formatter.printHelp(help, options);
    System.out.println();
}

From source file:org.languagetool.dev.dumpcheck.SentenceSourceChecker.java

private static CommandLine ensureCorrectUsageOrExit(String[] args) {
    Options options = new Options();
    options.addOption(Option.builder("l").longOpt("language").argName("code").hasArg()
            .desc("language code like 'en' or 'de'").required().build());
    options.addOption(Option.builder("d").longOpt("db-properties").argName("file").hasArg()
            .desc("A file to set database access properties. If not set, the output will be written to STDOUT. "
                    + "The file needs to set the properties dbUrl ('jdbc:...'), dbUser, and dbPassword. "
                    + "It can optionally define the batchSize for insert statements, which defaults to 1.")
            .build());/*from   ww w .j  a v  a2s  .  co m*/
    options.addOption(Option.builder().longOpt("rule-properties").argName("file").hasArg().desc(
            "A file to set rules which should be disabled per language (e.g. en=RULE1,RULE2 or all=RULE3,RULE4)")
            .build());
    options.addOption(Option.builder("r").longOpt("rule-ids").argName("id").hasArg()
            .desc("comma-separated list of rule-ids to activate").build());
    options.addOption(Option.builder().longOpt("also-enable-categories").argName("categories").hasArg()
            .desc("comma-separated list of categories to activate, additionally to rules activated anyway")
            .build());
    options.addOption(Option.builder("f").longOpt("file").argName("file").hasArg().desc(
            "an unpacked Wikipedia XML dump; (must be named *.xml, dumps are available from http://dumps.wikimedia.org/backup-index.html) "
                    + "or a Tatoeba CSV file filtered to contain only one language (must be named tatoeba-*). You can specify this option more than once.")
            .required().build());
    options.addOption(Option.builder().longOpt("max-sentences").argName("number").hasArg()
            .desc("maximum number of sentences to check").build());
    options.addOption(Option.builder().longOpt("max-errors").argName("number").hasArg()
            .desc("maximum number of errors, stop when finding more").build());
    options.addOption(Option.builder().longOpt("languagemodel").argName("indexDir").hasArg()
            .desc("directory with a '3grams' sub directory that contains an ngram index").build());
    options.addOption(Option.builder().longOpt("neuralnetworkmodel").argName("baseDir").hasArg()
            .desc("base directory for saved neural network models").build());
    options.addOption(Option.builder().longOpt("filter").argName("regex").hasArg()
            .desc("Consider only sentences that contain this regular expression (for speed up)").build());
    try {
        CommandLineParser parser = new DefaultParser();
        return parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Error: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(80);
        formatter.setSyntaxPrefix("Usage: ");
        formatter.printHelp(
                SentenceSourceChecker.class.getSimpleName() + " [OPTION]... --file <file> --language <code>",
                options);
        System.exit(1);
    }
    throw new IllegalStateException();
}

From source file:org.languagetool.dev.wikipedia.CheckWikipediaDump.java

@SuppressWarnings("AccessStaticViaInstance")
private static CommandLine ensureCorrectUsageOrExit(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("language").withArgName("code").hasArg()
            .withDescription("language code like 'en' or 'de'").isRequired().create("l"));
    options.addOption(OptionBuilder.withLongOpt("db-properties").withArgName("file").hasArg().withDescription(
            "A file to set database access properties. If not set, the output will be written to STDOUT. "
                    + "The file needs to set dbDriver (fully qualified driver class), dbUrl ('jdbc:...'), dbUser, and dbPassword.")
            .create("d"));
    options.addOption(OptionBuilder.withLongOpt("rule-properties").withArgName("file").hasArg().withDescription(
            "A file to set rules which should be disabled per language (e.g. en=RULE1,RULE2 or all=RULE3,RULE4)")
            .create());/*from  w  w w .  j  a  v  a 2s.co  m*/
    options.addOption(OptionBuilder.withLongOpt("rule-ids").withArgName("id").hasArg()
            .withDescription("comma-separated list of rule-ids to activate").create("r"));
    options.addOption(OptionBuilder.withLongOpt("file").withArgName("xmlfile").hasArg().withDescription(
            "an unpacked Wikipedia XML dump; dumps are available from http://dumps.wikimedia.org/backup-index.html")
            .isRequired().create("f"));
    options.addOption(OptionBuilder.withLongOpt("max-articles").withArgName("number").hasArg()
            .withDescription("maximum number of articles to check").create());
    options.addOption(OptionBuilder.withLongOpt("max-errors").withArgName("number").hasArg()
            .withDescription("maximum number of errors, stop when finding more").create());
    try {
        CommandLineParser parser = new GnuParser();
        return parser.parse(options, args);
    } catch (org.apache.commons.cli.ParseException e) {
        System.err.println("Error: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(80);
        formatter.setSyntaxPrefix("Usage: ");
        formatter.printHelp(
                CheckWikipediaDump.class.getSimpleName() + " [OPTION]... --file <xmlfile> --language <code>",
                options);
        System.exit(1);
    }
    return null;
}

From source file:org.linqs.psl.cli.Launcher.java

private static HelpFormatter getHelpFormatter() {
    HelpFormatter helpFormatter = new HelpFormatter();

    // Hack the option ordering to put argumentions without options first and then required options first.
    // infer and learn go first, then required, then just normal.
    helpFormatter.setOptionComparator(new Comparator<Option>() {
        @Override/*from  w  ww.  j a  v a  2  s.c  om*/
        public int compare(Option o1, Option o2) {
            String name1 = o1.getOpt();
            if (name1 == null) {
                name1 = o1.getLongOpt();
            }

            String name2 = o2.getOpt();
            if (name2 == null) {
                name2 = o2.getLongOpt();
            }

            if (name1.equals(OPERATION_INFER)) {
                return -1;
            }

            if (name2.equals(OPERATION_INFER)) {
                return 1;
            }

            if (name1.equals(OPERATION_LEARN)) {
                return -1;
            }

            if (name2.equals(OPERATION_LEARN)) {
                return 1;
            }

            if (o1.isRequired() && !o2.isRequired()) {
                return -1;
            }

            if (!o1.isRequired() && o2.isRequired()) {
                return 1;
            }

            return name1.compareTo(name2);
        }
    });

    helpFormatter.setWidth(100);

    return helpFormatter;
}

From source file:org.openrdf.console.Console.java

private static void printUsage(ConsoleIO cio, Options options) {
    cio.writeln("Sesame Console, an interactive shell based utility to communicate with Sesame repositories.");
    final HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(80);
    formatter.printHelp("start-console [OPTION] [repositoryID]", options);
    cio.writeln();/*from  ww  w .j a va  2s.c o m*/
    cio.writeln("For bug reports and suggestions, see http://www.openrdf.org/");
}

From source file:org.ow2.proactive.authentication.crypto.CreateCredentials.java

private static void displayHelp(Options options) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(135);
    hf.printHelp("create-cred" + Tools.shellExtension(), "", options, "", true);
    System.exit(2);//from   w  w w . j  a  v  a2 s  .c o  m
}

From source file:org.ow2.proactive.resourcemanager.utils.console.ResourceManagerController.java

public void load(String[] args) {

    Options options = new Options();

    Option help = new Option("h", "help", false, "Display this help");
    help.setRequired(false);/* w  ww .j  a v a  2s  .  c o m*/
    options.addOption(help);

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

    Option rmURL = new Option("u", "rmURL", true, "The Resource manager URL (default " + RM_DEFAULT_URL + ")");
    rmURL.setArgName("rmURL");
    rmURL.setArgs(1);
    rmURL.setRequired(false);
    options.addOption(rmURL);

    Option visual = new Option("g", "gui", false, "Start the console in a graphical view");
    rmURL.setRequired(false);
    options.addOption(visual);

    addCommandLineOptions(options);

    boolean displayHelp = false;

    try {
        String pwdMsg = null;

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

        if (cmd.hasOption("h")) {
            displayHelp = true;
        } else {
            if (cmd.hasOption("environment")) {
                model.setInitEnv(cmd.getOptionValue("environment"));
            }
            String url;
            if (cmd.hasOption("u")) {
                url = cmd.getOptionValue("u");
            } else {
                url = RM_DEFAULT_URL;
            }

            logger.info("Connecting to the RM on " + url);
            auth = RMConnection.join(url);
            logger.info("\t-> Connection established on " + url);

            if (cmd.hasOption("l")) {
                user = cmd.getOptionValue("l");
            }
            if (cmd.hasOption("credentials")) {
                if (cmd.getOptionValues("credentials").length == 1) {
                    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);
                    throw e;
                }
            } else {
                ConsoleReader console = new ConsoleReader(System.in, new PrintWriter(System.out));
                if (cmd.hasOption("l")) {
                    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 RM
                    RMAuthentication auth = RMConnection.join(url);
                    pubKey = auth.getPublicKey();
                    logger.info("Retrieved public key from Resource Manager 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 Resource Manager.");
                        logger.debug("", exc);
                        System.exit(1);
                    }
                }
                try {
                    this.credentials = Credentials.createCredentials(
                            new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd), pubKey);
                } catch (KeyException 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) {
        logger.debug("", e);
        displayHelp = true;
    } catch (RMException e) {
        logger.error(
                "Error at connection : " + e.getMessage() + newline + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(2);
    } catch (LoginException e) {
        logger.error(e.getMessage() + newline + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(3);
    } catch (Exception e) {
        logger.error(
                "An error has occurred : " + e.getMessage() + newline + "Shutdown the controller." + newline,
                e);
        logger.debug("", e);
        System.exit(4);
    }

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

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

From source file:org.ow2.proactive.resourcemanager.utils.RMStarter.java

private static void displayHelp() {
    logger.info("");
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(120);
    hf.printHelp("rm-start", options, true);
    logger.info("\n Notice : Without argument, the resource manager starts without any computing node.");
    System.exit(1);//from w w w  .  jav a 2  s.  c om
}