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

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

Introduction

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

Prototype

public void setOptionComparator(Comparator comparator) 

Source Link

Document

Set the comparator used to sort the options when they output in help text Passing in a null parameter will set the ordering to the default mode

Usage

From source file:org.eclipse.leshan.client.demo.LeshanClientDemo.java

public static void main(final String[] args) {

    // Define options for command line tools
    Options options = new Options();

    options.addOption("h", "help", false, "Display help information.");
    options.addOption("n", true,
            String.format("Set the endpoint name of the Client.\nDefault: the local hostname or '%s' if any.",
                    DEFAULT_ENDPOINT));//from ww w  .j a  v a  2  s.  c o m
    options.addOption("b", false, "If present use bootstrap.");
    options.addOption("lh", true, "Set the local CoAP address of the Client.\n  Default: any local address.");
    options.addOption("lp", true,
            "Set the local CoAP port of the Client.\n  Default: A valid port value is between 0 and 65535.");
    options.addOption("slh", true,
            "Set the secure local CoAP address of the Client.\nDefault: any local address.");
    options.addOption("slp", true,
            "Set the secure local CoAP port of the Client.\nDefault: A valid port value is between 0 and 65535.");
    options.addOption("u", true, "Set the LWM2M or Bootstrap server URL.\nDefault: localhost:5683.");
    options.addOption("i", true,
            "Set the LWM2M or Bootstrap server PSK identity in ascii.\nUse none secure mode if not set.");
    options.addOption("p", true,
            "Set the LWM2M or Bootstrap server Pre-Shared-Key in hexa.\nUse none secure mode if not set.");
    options.addOption("pos", true,
            "Set the initial location (latitude, longitude) of the device to be reported by the Location object. Format: lat_float:long_float");
    options.addOption("sf", true, "Scale factor to apply when shifting position. Default is 1.0.");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);

    // Parse arguments
    CommandLine cl = null;
    try {
        cl = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
        formatter.printHelp(USAGE, options);
        return;
    }

    // Print help
    if (cl.hasOption("help")) {
        formatter.printHelp(USAGE, options);
        return;
    }

    // Abort if unexpected options
    if (cl.getArgs().length > 0) {
        System.err.println("Unexpected option or arguments : " + cl.getArgList());
        formatter.printHelp(USAGE, options);
        return;
    }

    // Abort if we have not identity and key for psk.
    if ((cl.hasOption("i") && !cl.hasOption("p")) || !cl.hasOption("i") && cl.hasOption("p")) {
        System.err.println("You should precise identity and Pre-Shared-Key if you want to connect in PSK");
        formatter.printHelp(USAGE, options);
        return;
    }

    // Get endpoint name
    String endpoint;
    if (cl.hasOption("n")) {
        endpoint = cl.getOptionValue("n");
    } else {
        try {
            endpoint = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            endpoint = DEFAULT_ENDPOINT;
        }
    }

    // Get server URI
    String serverURI;
    if (cl.hasOption("u")) {
        if (cl.hasOption("i"))
            serverURI = "coaps://" + cl.getOptionValue("u");
        else
            serverURI = "coap://" + cl.getOptionValue("u");
    } else {
        if (cl.hasOption("i"))
            serverURI = "coaps://localhost:5684";
        else
            serverURI = "coap://leshan.eclipse.org:5683";
    }

    // get security info
    byte[] pskIdentity = null;
    byte[] pskKey = null;
    if (cl.hasOption("i") && cl.hasOption("p")) {
        pskIdentity = cl.getOptionValue("i").getBytes();
        pskKey = Hex.decodeHex(cl.getOptionValue("p").toCharArray());
    }

    // get local address
    String localAddress = null;
    int localPort = 0;
    if (cl.hasOption("lh")) {
        localAddress = cl.getOptionValue("lh");
    }
    if (cl.hasOption("lp")) {
        localPort = Integer.parseInt(cl.getOptionValue("lp"));
    }

    // get secure local address
    String secureLocalAddress = null;
    int secureLocalPort = 0;
    if (cl.hasOption("slh")) {
        secureLocalAddress = cl.getOptionValue("slh");
    }
    if (cl.hasOption("slp")) {
        secureLocalPort = Integer.parseInt(cl.getOptionValue("slp"));
    }

    Float latitude = null;
    Float longitude = null;
    Float scaleFactor = 1.0f;
    // get initial Location
    if (cl.hasOption("pos")) {
        try {
            String pos = cl.getOptionValue("pos");
            int colon = pos.indexOf(':');
            if (colon == -1 || colon == 0 || colon == pos.length() - 1) {
                System.err.println(
                        "Position must be a set of two floats separated by a colon, e.g. 48.131:11.459");
                formatter.printHelp(USAGE, options);
                return;
            }
            latitude = Float.valueOf(pos.substring(0, colon));
            longitude = Float.valueOf(pos.substring(colon + 1));
        } catch (NumberFormatException e) {
            System.err.println("Position must be a set of two floats separated by a colon, e.g. 48.131:11.459");
            formatter.printHelp(USAGE, options);
            return;
        }
    }
    if (cl.hasOption("sf")) {
        try {
            scaleFactor = Float.valueOf(cl.getOptionValue("sf"));
        } catch (NumberFormatException e) {
            System.err.println("Scale factor must be a float, e.g. 1.0 or 0.01");
            formatter.printHelp(USAGE, options);
            return;
        }
    }

    createAndStartClient(endpoint, localAddress, localPort, secureLocalAddress, secureLocalPort,
            cl.hasOption("b"), serverURI, pskIdentity, pskKey, latitude, longitude, scaleFactor);
}

From source file:org.eclipse.leshan.server.bootstrap.demo.LeshanBootstrapServerDemo.java

public static void main(String[] args) {
    // Define options for command line tools
    Options options = new Options();

    options.addOption("h", "help", false, "Display help information.");
    options.addOption("lh", "coaphost", true, "Set the local CoAP address.\n  Default: any local address.");
    options.addOption("lp", "coapport", true, "Set the local CoAP port.\n  Default: 5683.");
    options.addOption("slh", "coapshost", true,
            "Set the secure local CoAP address.\nDefault: any local address.");
    options.addOption("slp", "coapsport", true, "Set the secure local CoAP port.\nDefault: 5684.");
    options.addOption("wp", "webport", true, "Set the HTTP port for web server.\nDefault: 8080.");
    options.addOption("cfg", "configfile", true,
            "Set the filename for the configuration.\nDefault: " + BootstrapStoreImpl.DEFAULT_FILE + ".");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);

    // Parse arguments
    CommandLine cl = null;//from   w w w .  j  av  a2s. c o  m
    try {
        cl = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Print help
    if (cl.hasOption("help")) {
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Abort if unexpected options
    if (cl.getArgs().length > 0) {
        System.err.println("Unexpected option or arguments : " + cl.getArgList());
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Get local address
    String localAddress = System.getenv("COAPHOST");
    if (cl.hasOption("lh")) {
        localAddress = cl.getOptionValue("lh");
    }
    if (localAddress == null)
        localAddress = "0.0.0.0";
    String localPortOption = System.getenv("COAPPORT");
    if (cl.hasOption("lp")) {
        localPortOption = cl.getOptionValue("lp");
    }
    int localPort = LeshanServerBuilder.PORT;
    if (localPortOption != null) {
        localPort = Integer.parseInt(localPortOption);
    }

    // Get secure local address
    String secureLocalAddress = System.getenv("COAPSHOST");
    if (cl.hasOption("slh")) {
        secureLocalAddress = cl.getOptionValue("slh");
    }
    if (secureLocalAddress == null)
        secureLocalAddress = "0.0.0.0";
    String secureLocalPortOption = System.getenv("COAPSPORT");
    if (cl.hasOption("slp")) {
        secureLocalPortOption = cl.getOptionValue("slp");
    }
    int secureLocalPort = LeshanServerBuilder.PORT_DTLS;
    if (secureLocalPortOption != null) {
        secureLocalPort = Integer.parseInt(secureLocalPortOption);
    }

    // Get http port
    String webPortOption = System.getenv("WEBPORT");
    if (cl.hasOption("wp")) {
        webPortOption = cl.getOptionValue("wp");
    }
    int webPort = 8080;
    if (webPortOption != null) {
        webPort = Integer.parseInt(webPortOption);
    }

    String configFilename = System.getenv("CONFIGFILE");
    if (cl.hasOption("cfg")) {
        configFilename = cl.getOptionValue("cfg");
    }
    if (configFilename == null) {
        configFilename = BootstrapStoreImpl.DEFAULT_FILE;
    }

    try {
        createAndStartServer(webPort, localAddress, localPort, secureLocalAddress, secureLocalPort,
                configFilename);
    } catch (BindException e) {
        System.err.println(String.format(
                "Web port %s is already in use, you can change it using the 'webport' option.", webPort));
        formatter.printHelp(USAGE, null, options, FOOTER);
    } catch (Exception e) {
        LOG.error("Jetty stopped with unexcepted error ...", e);
    }
}

From source file:org.eclipse.leshan.server.cluster.LeshanClusterServer.java

public static void main(String[] args) {
    // Define options for command line tools
    Options options = new Options();

    options.addOption("h", "help", false, "Display help information.");
    options.addOption("n", "instanceID", true, "Sets the unique identifier of this instance in the cluster.");
    options.addOption("lh", "coaphost", true, "Sets the local CoAP address.\n  Default: any local address.");
    options.addOption("lp", "coapport", true, "Sets the local CoAP port.\n  Default: 5683.");
    options.addOption("slh", "coapshost", true,
            "Sets the local secure CoAP address.\nDefault: any local address.");
    options.addOption("slp", "coapsport", true, "Sets the local secure CoAP port.\nDefault: 5684.");
    options.addOption("r", "redis", true,
            "Sets the location of the Redis database. The URL is in the format of: 'redis://:password@hostname:port/db_number'\n\nDefault: 'redis://localhost:6379'.");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);

    // Parse arguments
    CommandLine cl = null;//from w w w  .j  a v  a  2  s.c o m
    try {
        cl = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Print help
    if (cl.hasOption("help")) {
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Abort if unexpected options
    if (cl.getArgs().length > 0) {
        System.err.println("Unexpected option or arguments : " + cl.getArgList());
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // get cluster instance Id
    String clusterInstanceId = System.getenv("INSTANCEID");
    if (cl.hasOption("n")) {
        clusterInstanceId = cl.getOptionValue("n");
    }
    if (clusterInstanceId == null) {
        System.err.println("InstanceId is mandatory !");
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // get local address
    String localAddress = System.getenv("COAPHOST");
    if (cl.hasOption("lh")) {
        localAddress = cl.getOptionValue("lh");
    }
    String localPortOption = System.getenv("COAPPORT");
    if (cl.hasOption("lp")) {
        localPortOption = cl.getOptionValue("lp");
    }
    int localPort = LeshanServerBuilder.PORT;
    if (localPortOption != null) {
        localPort = Integer.parseInt(localPortOption);
    }

    // get secure local address
    String secureLocalAddress = System.getenv("COAPSHOST");
    if (cl.hasOption("slh")) {
        secureLocalAddress = cl.getOptionValue("slh");
    }
    String secureLocalPortOption = System.getenv("COAPSPORT");
    if (cl.hasOption("slp")) {
        secureLocalPortOption = cl.getOptionValue("slp");
    }
    int secureLocalPort = LeshanServerBuilder.PORT_DTLS;
    if (secureLocalPortOption != null) {
        secureLocalPort = Integer.parseInt(secureLocalPortOption);
    }

    // get the Redis hostname:port
    String redisUrl = "redis://localhost:6379";
    if (cl.hasOption("r")) {
        redisUrl = cl.getOptionValue("r");
    }

    try {
        createAndStartServer(clusterInstanceId, localAddress, localPort, secureLocalAddress, secureLocalPort,
                redisUrl);
    } catch (Exception e) {
        LOG.error("Jetty stopped with unexcepted error ...", e);
    }
}

From source file:org.eclipse.leshan.server.demo.LeshanServerDemo.java

public static void main(String[] args) {
    // Define options for command line tools
    Options options = new Options();

    options.addOption("h", "help", false, "Display help information.");
    options.addOption("lh", "coaphost", true, "Set the local CoAP address.\n  Default: any local address.");
    options.addOption("lp", "coapport", true, "Set the local CoAP port.\n  Default: 5683.");
    options.addOption("slh", "coapshost", true,
            "Set the secure local CoAP address.\nDefault: any local address.");
    options.addOption("slp", "coapsport", true, "Set the secure local CoAP port.\nDefault: 5684.");
    options.addOption("wp", "webport", true, "Set the HTTP port for web server.\nDefault: 8080.");
    options.addOption("r", "redis", true,
            "Set the location of the Redis database for running in cluster mode. The URL is in the format of: 'redis://:password@hostname:port/db_number'\nExample without DB and password: 'redis://localhost:6379'\nDefault: none, no Redis connection.");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);

    // Parse arguments
    CommandLine cl = null;/*from w  ww .  j av  a 2  s  .com*/
    try {
        cl = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Print help
    if (cl.hasOption("help")) {
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // Abort if unexpected options
    if (cl.getArgs().length > 0) {
        System.err.println("Unexpected option or arguments : " + cl.getArgList());
        formatter.printHelp(USAGE, null, options, FOOTER);
        return;
    }

    // get local address
    String localAddress = System.getenv("COAPHOST");
    if (cl.hasOption("lh")) {
        localAddress = cl.getOptionValue("lh");
    }
    String localPortOption = System.getenv("COAPPORT");
    if (cl.hasOption("lp")) {
        localPortOption = cl.getOptionValue("lp");
    }
    int localPort = LeshanServerBuilder.PORT;
    if (localPortOption != null) {
        localPort = Integer.parseInt(localPortOption);
    }

    // get secure local address
    String secureLocalAddress = System.getenv("COAPSHOST");
    if (cl.hasOption("slh")) {
        secureLocalAddress = cl.getOptionValue("slh");
    }
    String secureLocalPortOption = System.getenv("COAPSPORT");
    if (cl.hasOption("slp")) {
        secureLocalPortOption = cl.getOptionValue("slp");
    }
    int secureLocalPort = LeshanServerBuilder.PORT_DTLS;
    if (secureLocalPortOption != null) {
        secureLocalPort = Integer.parseInt(secureLocalPortOption);
    }

    // get http port
    String webPortOption = System.getenv("WEBPORT");
    if (cl.hasOption("wp")) {
        webPortOption = cl.getOptionValue("wp");
    }
    int webPort = 8080;
    if (webPortOption != null) {
        webPort = Integer.parseInt(webPortOption);
    }

    // get the Redis hostname:port
    String redisUrl = null;
    if (cl.hasOption("r")) {
        redisUrl = cl.getOptionValue("r");
    }

    try {
        createAndStartServer(webPort, localAddress, localPort, secureLocalAddress, secureLocalPort, redisUrl);
    } catch (BindException e) {
        System.err.println(String
                .format("Web port %s is alreay used, you could change it using 'webport' option.", webPort));
        formatter.printHelp(USAGE, null, options, FOOTER);
    } catch (Exception e) {
        LOG.error("Jetty stopped with unexcepted error ...", e);
    }
}

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

private boolean handleCommandLine(String instanceLoc) {
    CommandLine commandLine = getCommandLine();
    if (commandLine == null) {
        return false;
    }//  w  ww .ja va  2s . c o  m
    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.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  . ja  va 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.lockss.devtools.RunKbartReport.java

/**
 * Print a usage message.//from  www.j  av  a2  s.c o  m
 * @param error whether a parsing error provoked this usage display
 */
private static void usage(boolean error) {
    HelpFormatter help = new HelpFormatter();
    // Set a comparator that will output the options in the order
    // they were specified above
    help.setOptionComparator(new Comparator<Option>() {
        public int compare(Option option, Option option1) {
            Integer i = optionList.indexOf(option);
            Integer i1 = optionList.indexOf(option1);
            return i.compareTo(i1);
        }
    });
    // Print blank line
    System.err.println();
    help.printHelp("RunKbartReport", options, true);
    if (error) {
        for (Object o : options.getRequiredOptions()) {
            System.err.format("Note that the -%s option is required\n", o);
        }
    }
    // Show defaults
    System.err.println("");
    //System.err.println("Default output format is "+defaultOutput);
    //System.err.println("Default data format is "+DEFAULT_COLUMN_ORDERING);

    // Print data format options
    System.err.format("Data format argument must be one of the following " + "identifiers (default %s):\n",
            DEFAULT_COLUMN_ORDERING.name());
    for (PredefinedColumnOrdering ord : PredefinedColumnOrdering.values()) {
        System.err.format("  %s (%s)\n", ord.name(), ord.description);
    }
    System.err.format("\nInput file should be UTF-8 encoded and include a "
            + "header row with field names matching KBART field names or any of the " + "following: %s.\n\n",
            StringUtils.join(nonKbartFields, ", "));
    System.exit(0);
}

From source file:org.lockss.tdb.HelpOption.java

/**
 * <p>//from w w w  .j a  v  a 2 s.  c  o m
 * If the help option has been requested on the command line, displays a usage
 * and help message to {@link System#out} <b>and then exits with
 * {@link System#exit(int)} and a return code of <code>0</code></b>.
 * </p>
 * 
 * @param cmd
 *          A {@link CommandLineAccessor} instance.
 * @param options
 *          A Commons CLI {@link Options} instance (not an options map).
 * @param clazz
 *          The {@link Class} instance of the program with a main method.
 * @since 1.67
 */
public static void processCommandLine(CommandLineAccessor cmd, Options options, Class<?> clazz) {
    if (cmd.hasOption(KEY_HELP)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setOptionComparator(new LongOptComparator());
        formatter.printHelp("java " + clazz.getName(), options);
        System.exit(0);
    }
}

From source file:org.mitre.secretsharing.cli.cmd.RootCommand.java

@Override
public void showHelp(PrintStream out) {
    super.showHelp(out);

    out.println();/*from w  w  w  .j  a v  a  2  s . com*/

    Options cmds = new Options();
    for (Command c : Commands.subCommands()) {
        cmds.addOption(null, c.getName(), false, c.getDescription());
    }

    HelpFormatter h = new HelpFormatter();
    h.setSyntaxPrefix("");
    h.setLongOptPrefix("");
    h.setOptionComparator(new Comparator<Option>() {
        @Override
        public int compare(Option o1, Option o2) {
            Integer p1 = Commands.names().indexOf(o1.getLongOpt());
            Integer p2 = Commands.names().indexOf(o2.getLongOpt());
            return p1.compareTo(p2);
        }
    });
    h.printHelp(new PrintWriter(out, true), 80, "Valid Commands:", "", cmds, 12, 12, getActualHelpFooter());
    out.flush();
}

From source file:org.openscience.jmol.app.JmolApp.java

private void checkOptions(CommandLine line, Options options) {
    if (line.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setOptionComparator(new OptSort());
        formatter.printHelp("Jmol", options);

        // now report on the -D options
        System.out.println();/*from  w  ww  .  ja  va2  s .co m*/
        System.out.println(GT._("For example:"));
        System.out.println();
        System.out.println("Jmol -ions myscript.spt -w JPEG:myfile.jpg > output.txt");
        System.out.println();
        System.out.println(GT._(
                "The -D options are as follows (defaults in parenthesis) and must be called preceding '-jar Jmol.jar':"));
        System.out.println();
        System.out.println("  cdk.debugging=[true|false] (false)");
        System.out.println("  cdk.debug.stdout=[true|false] (false)");
        System.out.println("  display.speed=[fps|ms] (ms)");
        //System.out.println("  JmolConsole=[true|false] (true)");
        System.out.println("  logger.debug=[true|false] (false)");
        System.out.println("  logger.error=[true|false] (true)");
        System.out.println("  logger.fatal=[true|false] (true)");
        System.out.println("  logger.info=[true|false] (true)");
        System.out.println("  logger.logLevel=[true|false] (false)");
        System.out.println("  logger.warn=[true|false] (true)");
        System.out.println("  plugin.dir (unset)");
        System.out.println("  user.language=[ca|cs|de|en_GB|en_US|es|fr|hu|it|ko|nl|pt_BR|tr|zh_TW] (en_US)");

        System.exit(0);
    }

    if (line.hasOption("a")) {
        autoAnimationDelay = PT.parseFloat(line.getOptionValue("a"));
        if (autoAnimationDelay > 10)
            autoAnimationDelay /= 1000;
        Logger.info("setting autoAnimationDelay to " + autoAnimationDelay + " seconds");
    }

    // Process more command line arguments
    // these are also passed to vwr

    // debug mode
    if (line.hasOption("d")) {
        Logger.setLogLevel(Logger.LEVEL_DEBUG);
    }

    // note that this is set up so that if JmolApp is 
    // invoked with just new JmolApp(), we can 
    // set options ourselves. 

    info.put(isDataOnly ? "JmolData" : "Jmol", Boolean.TRUE);

    // kiosk mode -- no frame

    if (line.hasOption("k"))
        info.put("isKiosk", Boolean.valueOf(isKiosk = true));

    // port for JSON mode communication

    if (line.hasOption("P"))
        port = PT.parseInt(line.getOptionValue("P"));
    if (port > 0)
        info.put("port", Integer.valueOf(port));

    // print command output only (implies silent)

    if (line.hasOption("p"))
        isPrintOnly = true;
    if (isPrintOnly) {
        info.put("printOnly", Boolean.TRUE);
        isSilent = true;
    }

    // silent startup
    if (line.hasOption("i"))
        isSilent = true;
    if (isSilent)
        info.put("silent", Boolean.TRUE);

    // output to sysout
    if (line.hasOption("o"))
        haveConsole = false;
    if (!haveConsole) // might also be set in JmolData
        info.put("noConsole", Boolean.TRUE);

    // transparent background
    if (line.hasOption("b"))
        info.put("transparentBackground", Boolean.TRUE);

    // restricted file access
    if (line.hasOption("R"))
        info.put("access:NONE", Boolean.TRUE);

    // restricted file access (allow reading of SPT files)
    if (line.hasOption("r"))
        info.put("access:READSPT", Boolean.TRUE);

    // independent command thread
    if (line.hasOption("t"))
        info.put("useCommandThread", Boolean.TRUE);

    // list commands during script operation
    if (line.hasOption("l"))
        info.put("listCommands", Boolean.TRUE);

    // no splash screen
    if (line.hasOption("L"))
        splashEnabled = false;

    // check script only -- don't open files
    if (line.hasOption("c"))
        info.put("check", Boolean.TRUE);
    if (line.hasOption("C"))
        info.put("checkLoad", Boolean.TRUE);

    // menu file
    if (line.hasOption("m"))
        menuFile = line.getOptionValue("m");

    // run pre Jmol script
    if (line.hasOption("J"))
        script1 = line.getOptionValue("J");

    // use SparshUI
    if (line.hasOption("M"))
        info.put("multitouch", line.getOptionValue("M"));

    // run script from file
    if (line.hasOption("s")) {
        scriptFilename = line.getOptionValue("s");
    }

    // run post Jmol script
    if (line.hasOption("j")) {
        script2 = line.getOptionValue("j");
    }

    //Point b = null;    
    if (haveDisplay && historyFile != null) {
        Dimension size;
        String vers = System.getProperty("java.version");
        if (vers.compareTo("1.1.2") < 0) {
            System.out.println("!!!WARNING: Swing components require a " + "1.1.2 or higher version VM!!!");
        }

        if (!isKiosk) {
            size = historyFile.getWindowSize("Jmol");
            if (size != null) {
                startupWidth = size.width;
                startupHeight = size.height;
            }
            historyFile.getWindowBorder("Jmol");
            // first one is just approximate, but this is set in doClose()
            // so it will reset properly -- still, not perfect
            // since it is always one step behind.
            //if (b == null || b.x > 50)
            border = new Point(12, 116);
            //else
            //border = new Point(b.x, b.y);
            // note -- the first time this is run after changes it will not work
            // because there is a bootstrap problem.
        }
    }
    // INNER frame dimensions
    int width = (isKiosk ? 0 : 500);
    int height = 500;

    if (line.hasOption("g")) {
        String geometry = line.getOptionValue("g");
        int indexX = geometry.indexOf('x');
        if (indexX > 0) {
            width = PT.parseInt(geometry.substring(0, indexX));
            height = PT.parseInt(geometry.substring(indexX + 1));
        } else {
            width = height = PT.parseInt(geometry);
        }
        startupWidth = -1;
    }

    if (startupWidth <= 0 || startupHeight <= 0) {
        if (haveDisplay && !isKiosk && border != null) {
            startupWidth = width + border.x;
            startupHeight = height + border.y;
        } else {
            startupWidth = width;
            startupHeight = height;
        }
    }

    // write image to clipboard or image file
    if (line.hasOption("w")) {
        int quality = -1;
        if (line.hasOption("q"))
            quality = PT.parseInt(line.getOptionValue("q"));
        String type_name = line.getOptionValue("w");
        if (type_name != null) {
            if (type_name.length() == 0)
                type_name = "JPG:jpg";
            if (type_name.indexOf(":") < 0)
                type_name += ":jpg";
            int i = type_name.indexOf(":");
            String type = type_name.substring(0, i).toUpperCase();
            type_name = type_name.substring(i + 1).trim();
            if (type.indexOf(" ") >= 0) {
                quality = PT.parseInt(type.substring(type.indexOf(" ")).trim());
                type.substring(0, type.indexOf(" "));
            }
            if (GraphicsEnvironment.isHeadless()) {
                Map<String, Object> data = new Hashtable<String, Object>();
                data.put("fileName", type_name);
                data.put("type", type);
                data.put("quality", Integer.valueOf(quality));
                data.put("width", Integer.valueOf(width));
                data.put("height", Integer.valueOf(height));
                info.put("headlessImage", data);
            } else
                script2 += ";write image " + (width > 0 && height > 0 ? width + " " + height : "") + " " + type
                        + " " + quality + " " + PT.esc(type_name);
        }
    }
    if (GraphicsEnvironment.isHeadless())
        info.put("headlistMaxTimeMs",
                Integer.valueOf(1000 * (line.hasOption("T") ? PT.parseInt(line.getOptionValue("T")) : 60)));

    // the next three are coupled -- if the -n command line option is 
    // given, but -I is not, then the -x is added, but not vice-versa. 
    // however, if this is an application-embedded object, then
    // it is ok to have no display and no exit.

    // scanner input
    if (line.hasOption("I"))
        scanInput = true;

    boolean exitUponCompletion = false;
    if (line.hasOption("n")) {
        // no display (and exit)
        haveDisplay = false;
        exitUponCompletion = !scanInput;
    }
    if (line.hasOption("x"))
        // exit when script completes (or file is read)
        exitUponCompletion = true;

    if (!haveDisplay)
        info.put("noDisplay", Boolean.TRUE);
    if (exitUponCompletion) {
        info.put("exit", Boolean.TRUE);
        script2 += ";exitJmol;";
    }

}