Example usage for org.apache.commons.cli Option setType

List of usage examples for org.apache.commons.cli Option setType

Introduction

In this page you can find the example usage for org.apache.commons.cli Option setType.

Prototype

public void setType(Object type) 

Source Link

Document

Sets the type of this Option.

Usage

From source file:pl.mcpg.nbtjeditor.Start.java

public static void main(String[] args) {
    // if there are any arguments, parse them
    if (args.length > 0) {
        Options options = new Options();

        Option help = new Option("h", "help", false, "Displays this help message");

        Option openfile = new Option("f", "file", true, "Opens requested file at startup");
        openfile.setArgName("filename");
        openfile.setType(String.class);
        options.addOption(openfile);//from   ww  w .j  a  v a  2 s .c o m

        options.addOption(help);
        options.addOption(openfile);

        CommandLineParser parser = new DefaultParser();
        CommandLine commandLine = null;
        try {
            commandLine = parser.parse(options, args);
        } catch (ParseException e) {
            displayError("Couldn't parse command line arguments!", e);
        }
        if (commandLine != null) {
            // display help message
            if (commandLine.hasOption("h")) {
                HelpFormatter helpFormatter = new HelpFormatter();
                helpFormatter.printHelp("nbt-jeditor", "\nCommand line arguments for NBT JEditor", options,
                        "\nIssues? Report them at GitHub: https://github.com/Mcpg/nbt-jeditor/issues", true);
                System.exit(0);
            }
            if (commandLine.hasOption("f")) {
                // find the file and if it doesn't exist display message and set it to null
                String value = commandLine.getOptionValue("f");
                if (value != null && !value.isEmpty()) {
                    fileToOpen = new File(value);
                    if (!fileToOpen.exists()) {
                        displayError("Requested file '" + value + "' doesn't exist.");
                        fileToOpen = null;
                    }
                }
            }
        }
    }
    launch(args);
}

From source file:sorcer.launcher.Sorcer.java

private static Options buildOptions() {
    Options options = new Options();
    Option wait = new Option(WAIT, "wait", true,
            "Wait style, one of:\n" + "'no' - exit immediately, forces forked mode\n"
                    + "'start' - wait until sorcer starts, then exit, forces forked mode\n"
                    + "'end' - wait until sorcer finishes, stopping launcher also stops SORCER");
    wait.setType(WaitMode.class);
    wait.setArgs(1);//from   ww w. j  a v a2  s  .co  m
    wait.setArgName("wait-mode");
    options.addOption(wait);

    Option logs = new Option(LOGS, true, "Directory for logs");
    logs.setType(File.class);
    logs.setArgs(1);
    logs.setArgName("log-dir");
    options.addOption(logs);

    Option debug = new Option(DEBUG, true, "Add debug option to JVM");
    debug.setType(Boolean.class);
    debug.setArgs(1);
    debug.setArgName("port");
    options.addOption(debug);

    //see sorcer.launcher.Profile
    Option profile = new Option(PROFILE, "profile", true, "Profile, one of [sorcer, rio, mix] or a path");
    profile.setArgs(1);
    profile.setType(String.class);
    profile.setArgName("profile");
    options.addOption(profile);

    String modeDesc = "Select start mode, one of:\n" + Mode.preferDirect.paramValue
            + " - default, prefer current JVM, start in forked if debug is enabled or required environment variable is not set\n"
            + Mode.forceDirect.paramValue + " - try current JVM, exit on failure\n" + Mode.preferFork.paramValue
            + " - prefer new process, try in current JVM if cannot run a process (e.g. insufficient privileges)\n"
            + Mode.forceFork.paramValue + " try new process, exit on failure";
    Option mode = new Option(MODE, "mode", true, modeDesc);
    mode.setType(Boolean.class);
    mode.setArgs(1);
    mode.setArgName("mode");
    options.addOption(mode);
    options.addOption("h", "help", false, "Print this help");

    Option rio = new Option(RIO,
            "List of opstrings to be started by the Rio Monitor (opstring) separated by the system path separator ("
                    + File.pathSeparator + ")");
    rio.setArgs(1);
    rio.setArgName("opstrings");
    rio.setType(String.class);
    options.addOption(rio);

    return options;
}

From source file:sorcer.tools.shell.cmds.BootCmd.java

private Options buildOptions() {
    Options options = new Options();
    Option logs = new Option(LOGS, true, "Directory for logs");
    logs.setType(File.class);
    logs.setArgs(1);/*w ww. j a  v  a 2  s.  co  m*/
    logs.setArgName("log-dir");
    options.addOption(logs);

    //see sorcer.launcher.Profile
    Option profile = new Option(PROFILE, "profile", true, "Profile, one of [sorcer, rio, mix] or a path");
    profile.setArgs(1);
    profile.setType(String.class);
    profile.setArgName("profile");
    options.addOption(profile);

    Option rio = new Option(RIO,
            "List of opstrings to be started by the Rio Monitor (opstring) separated by the system path separator ("
                    + File.pathSeparator + ")");
    rio.setArgs(1);
    rio.setArgName("opstrings");
    rio.setType(String.class);
    options.addOption(rio);

    Option all = new Option(ALL,
            "List of opstrings to be started by the Rio Monitor (opstring) separated by the system path separator ("
                    + File.pathSeparator + ")");
    all.setArgs(1);
    all.setArgName("all");
    all.setType(String.class);
    options.addOption(all);

    return options;
}