Example usage for org.apache.commons.cli OptionGroup OptionGroup

List of usage examples for org.apache.commons.cli OptionGroup OptionGroup

Introduction

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

Prototype

OptionGroup

Source Link

Usage

From source file:com.cjmcgraw.markupvalidator.args.CLIArgumentParser.java

private OptionGroup createGroup(Option... options) {
    OptionGroup group = new OptionGroup();

    for (Option option : options)
        group.addOption(option);//from w  w  w .  ja va2  s.co  m

    return group;
}

From source file:de.thetaphi.forbiddenapis.cli.CliMain.java

public CliMain(String... args) throws ExitException {
    final OptionGroup required = new OptionGroup();
    required.setRequired(true);//from   ww  w. j  av a 2s. c o m
    required.addOption(dirOpt = Option.builder("d").desc(
            "directory with class files to check for forbidden api usage; this directory is also added to classpath")
            .longOpt("dir").hasArg().argName("directory").build());
    required.addOption(
            versionOpt = Option.builder("V").desc("print product version and exit").longOpt("version").build());
    required.addOption(helpOpt = Option.builder("h").desc("print this help").longOpt("help").build());

    final Options options = new Options();
    options.addOptionGroup(required);
    options.addOption(classpathOpt = Option.builder("c")
            .desc("class search path of directories and zip/jar files").longOpt("classpath").hasArgs()
            .valueSeparator(File.pathSeparatorChar).argName("path").build());
    options.addOption(includesOpt = Option.builder("i").desc(
            "ANT-style pattern to select class files (separated by commas or option can be given multiple times, defaults to '**/*.class')")
            .longOpt("includes").hasArgs().valueSeparator(',').argName("pattern").build());
    options.addOption(excludesOpt = Option.builder("e").desc(
            "ANT-style pattern to exclude some files from checks (separated by commas or option can be given multiple times)")
            .longOpt("excludes").hasArgs().valueSeparator(',').argName("pattern").build());
    options.addOption(signaturesfileOpt = Option.builder("f")
            .desc("path to a file containing signatures (option can be given multiple times)")
            .longOpt("signaturesfile").hasArg().argName("file").build());
    options.addOption(bundledsignaturesOpt = Option.builder("b").desc(
            "name of a bundled signatures definition (separated by commas or option can be given multiple times)")
            .longOpt("bundledsignatures").hasArgs().valueSeparator(',').argName("name").build());
    options.addOption(suppressannotationsOpt = Option.builder().desc(
            "class name or glob pattern of annotation that suppresses error reporting in classes/methods/fields (separated by commas or option can be given multiple times)")
            .longOpt("suppressannotation").hasArgs().valueSeparator(',').argName("classname").build());
    options.addOption(internalruntimeforbiddenOpt = Option.builder().desc(String.format(Locale.ENGLISH,
            "DEPRECATED: forbids calls to non-portable runtime APIs; use bundled signatures '%s' instead",
            BS_JDK_NONPORTABLE)).longOpt("internalruntimeforbidden").build());
    options.addOption(allowmissingclassesOpt = Option.builder()
            .desc("don't fail if a referenced class is missing on classpath").longOpt("allowmissingclasses")
            .build());
    options.addOption(allowunresolvablesignaturesOpt = Option.builder()
            .desc("don't fail if a signature is not resolving").longOpt("allowunresolvablesignatures").build());

    try {
        this.cmd = new DefaultParser().parse(options, args);
        if (cmd.hasOption(helpOpt.getLongOpt())) {
            printHelp(options);
            throw new ExitException(EXIT_SUCCESS);
        }
        if (cmd.hasOption(versionOpt.getLongOpt())) {
            printVersion();
            throw new ExitException(EXIT_SUCCESS);
        }
    } catch (org.apache.commons.cli.ParseException pe) {
        printHelp(options);
        throw new ExitException(EXIT_ERR_CMDLINE);
    }
}

From source file:eu.itesla_project.online.tools.OnlineWorkflowCommand.java

@Override
public Options getOptions() {
    Options opts = new Options();

    OptionGroup og = new OptionGroup();
    og.setRequired(true);/* ww  w  .  j  a  v  a 2s .c  o m*/

    og.addOption(Option.builder().longOpt(START_CMD).desc("start new online workflow").build());

    og.addOption(Option.builder().longOpt(SHUTDOWN_CMD).desc("shutdown online workflow application").build());
    opts.addOptionGroup(og);

    opts.addOption(Option.builder().longOpt(HOST).desc("jmx host").hasArg().argName("HOST").build());
    opts.addOption(Option.builder().longOpt(PORT).desc("jmx port").hasArg().argName("PORT").build());

    opts.addOption(Option.builder().longOpt(BASE_CASE).desc("Base case").hasArg().argName(BASE_CASE).build());

    opts.addOption(Option.builder().longOpt(TIME_HORIZON).desc("time horizon for the online analysis").hasArg()
            .argName(TIME_HORIZON).build());

    opts.addOption(Option.builder().longOpt(BASE_CASE).desc("Basecase to be analyzed").hasArg()
            .argName(BASE_CASE).build());

    opts.addOption(Option.builder().longOpt(STATES).desc("States number").hasArg().argName(STATES).build());

    opts.addOption(
            Option.builder().longOpt(WORKFLOW_ID).desc("offline workflow id that produced the security rules")
                    .hasArg().argName(WORKFLOW_ID).build());

    opts.addOption(Option.builder().longOpt(HISTODB_INTERVAL)
            .desc("interval of historical data to be used for WCA").hasArg().argName(HISTODB_INTERVAL).build());

    opts.addOption(Option.builder().longOpt(THREADS).desc("Executing threads number").hasArg().argName(THREADS)
            .build());

    opts.addOption(Option.builder().longOpt(FEANALYSIS_ID).desc("id of the forecast error analysis").hasArg()
            .argName(FEANALYSIS_ID).build());

    opts.addOption(Option.builder().longOpt(RULES_PURITY).desc("purity threshold for the security rules")
            .hasArg().argName(RULES_PURITY).build());

    opts.addOption(Option.builder().longOpt(STORE_STATES).desc("store states").build());

    opts.addOption(Option.builder().longOpt(ANALYSE_BASECASE).desc("analyse basecase").build());

    opts.addOption(Option.builder().longOpt(VALIDATION).desc("validation").build());

    opts.addOption(Option.builder().longOpt(SECURITY_INDEXES)
            .desc("sub list of security index types to use, use ALL for using all of them").hasArg()
            .argName("INDEX_TYPE,INDEX_TYPE,...").build());

    opts.addOption(Option.builder().longOpt(BASECASES_INTERVAL)
            .desc("interval for basecases to be considered; when set, overrides base-case parameter").hasArg()
            .argName(BASECASES_INTERVAL).build());

    opts.addOption(Option.builder().longOpt(CASE_TYPE).desc("the type (FO/SN) of the base case").hasArg()
            .argName(CASE_TYPE).build());

    opts.addOption(
            Option.builder().longOpt(COUNTRIES).desc("the countries of the base case, separated by comma")
                    .hasArg().argName("COUNTRY,COUNTRY,...").build());

    opts.addOption(Option.builder().longOpt(MERGE_OPTIMIZED).desc("merge optimized").build());

    opts.addOption(Option.builder().longOpt(LIMIT_REDUCTION).desc("limits reduction").hasArg()
            .argName(LIMIT_REDUCTION).build());

    opts.addOption(Option.builder().longOpt(HANDLE_VIOLATION_IN_N).desc("handle violation in n").build());

    opts.addOption(Option.builder().longOpt(CONSTRAINT_MARGIN).desc("constraint margin").hasArg()
            .argName(CONSTRAINT_MARGIN).build());

    opts.addOption(Option.builder().longOpt(CASE_FILE)
            .desc("case file: Note: parameter " + CASE_FILE + "cannot be used together with parameters "
                    + BASE_CASE + ", " + CASE_TYPE + ", " + COUNTRIES + ", " + BASECASES_INTERVAL)
            .hasArg().argName(CASE_FILE).build());

    return opts;
}

From source file:net.sourceforge.docfetcher.CommandLineHandler.java

@SuppressWarnings("static-access")
private static Options createOptions() {
    Options options = new Options();

    // Windows registry manipulation options
    OptionGroup registryGroup = new OptionGroup();
    registryGroup.addOption(OptionBuilder.withLongOpt(REGISTER_CONTEXTMENU)
            .withDescription("add search entry to Windows explorer contextmenu").create());
    registryGroup.addOption(OptionBuilder.withLongOpt(UNREGISTER_CONTEXTMENU)
            .withDescription("remove search entry from Windows explorer contextmenu").create());
    options.addOptionGroup(registryGroup);

    // Text extraction options
    OptionGroup extractGroup = new OptionGroup();
    extractGroup.addOption(OptionBuilder.withLongOpt(EXTRACT)
            .withDescription("extract text from documents to textfile").hasOptionalArgs().create());
    extractGroup.addOption(OptionBuilder.withLongOpt(EXTRACT_DIR)
            .withDescription("extract text from documents to directory").hasOptionalArgs().create());
    options.addOptionGroup(extractGroup);

    // Inclusion and exclusion filter options
    options.addOption(//from   w  ww .  j  a v a  2 s . c om
            OptionBuilder.withLongOpt(INCLUDE).withDescription("regex inclusion filter for text extraction")
                    .hasArg().withArgName(REGEX).create());
    options.addOption(
            OptionBuilder.withLongOpt(EXCLUDE).withDescription("regex exclusion filter for text extraction")
                    .hasArg().withArgName(REGEX).create());

    // Version info and help options
    options.addOption("h", "help", false, "print this help and exit");
    options.addOption("v", "version", false, "print version number and exit");

    return options;
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

private Options initialize(String[] args) {
    OptionGroup group = new OptionGroup();

    Option helpOpt = new Option(null, "help", false, "this message");
    helpOpt.setArgs(2);/*from w ww  .jav a 2s.  c o m*/
    helpOpt.setValueSeparator(',');
    group.addOption(helpOpt);

    Option opt = new Option("sh", "shutdown", true, "the service to shut down");
    opt.setArgs(2);
    opt.setValueSeparator(',');
    group.addOption(opt);

    Option updateOpt = new Option(null, "dbupdate", false, "the database update parameters");
    updateOpt.setArgs(3);
    updateOpt.setValueSeparator(',');
    group.addOption(updateOpt);

    Option unbindOpt = new Option(null, "unbind", true,
            "the unbind option to be used ONLY if the service cannot be shut down gracefully");
    unbindOpt.setArgs(2);
    unbindOpt.setValueSeparator(',');
    group.addOption(unbindOpt);
    addOptions(group);

    Options options = new Options();
    options.addOptionGroup(group);
    return options;
}

From source file:com.github.braully.graph.BatchExecuteOperation.java

void processMain(String... args) {
    GraphCaratheodoryHeuristic.verbose = false;

    Options options = new Options();

    OptionGroup exec = new OptionGroup();
    exec.setRequired(false);/*from ww  w  .ja v a2 s  . c o  m*/
    IGraphOperation[] opers = getOperations();
    Option[] execs = new Option[opers.length];
    for (int i = 0; i < opers.length; i++) {
        IGraphOperation oper = opers[i];
        execs[i] = new Option("" + i, false, oper.getName());
        options.addOption(execs[i]);
    }
    //        options.addOptionGroup(exec);

    Option input = new Option("i", "input", true, "input file or directory");
    options.addOption(input);

    Option cont = new Option("c", "continue", false, "continue from last processing");
    cont.setRequired(false);
    options.addOption(cont);

    Option verb = new Option("v", "verbose", false, "verbose processing");
    options.addOption(verb);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(false);
    options.addOption(output);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    //        input.setRequired(true);
    //        exec.setRequired(true);
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("BatchExecuteOperation", options);
        System.exit(1);
        return;
    }

    boolean contProcess = false;

    String inputFilePath = cmd.getOptionValue("input");
    if (inputFilePath == null) {
        inputFilePath = getDefaultInput();
    }
    if (inputFilePath == null) {
        return;
    }

    if (cmd.hasOption("continue")) {
        contProcess = true;
    }

    if (cmd.hasOption("verbose")) {
        verbose = true;
    }

    List<IGraphOperation> operationsToExecute = new ArrayList<IGraphOperation>();
    for (int i = 0; i < opers.length; i++) {
        IGraphOperation oper = opers[i];
        String value = execs[i].getOpt();
        if (cmd.hasOption(value)) {
            operationsToExecute.add(oper);
        }
    }

    if (operationsToExecute.isEmpty()) {
        operationsToExecute.add(opers[0]);
        //            formatter.printHelp("BatchExecuteOperation", options);
        //            System.exit(1);
        //            return;
    }
    File dir = new File(inputFilePath);
    if (dir.isDirectory()) {
        processDirectory(operationsToExecute, inputFilePath, contProcess);
    } else if (inputFilePath.toLowerCase().endsWith(".mat")) {
        try {
            for (IGraphOperation operation : operationsToExecute) {
                processFileMat(operation, dir);
            }
        } catch (Exception ex) {
            Logger.getLogger(BatchExecuteOperation.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else if (inputFilePath.toLowerCase().endsWith(".g6")) {
        try {
            for (IGraphOperation operation : operationsToExecute) {
                processFileG6(operation, dir);
            }
        } catch (Exception ex) {
            Logger.getLogger(BatchExecuteOperation.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else if (inputFilePath.toLowerCase().endsWith(".g6.gz")) {
        try {
            for (IGraphOperation operation : operationsToExecute) {
                processFileG6GZ(operation, dir);
            }
        } catch (Exception ex) {
            Logger.getLogger(BatchExecuteOperation.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.net2plan.cli.CLINet2Plan.java

/**
 * Default constructor.//w  w  w .j a v  a2  s  . c o m
 *
 * @param args Command-line arguments
 */
public CLINet2Plan(String args[]) {
    try {
        SystemUtils.configureEnvironment(CLINet2Plan.class, UserInterface.CLI);

        for (Class<? extends Plugin> plugin : PluginSystem.getPlugins(ICLIModule.class)) {
            try {
                ICLIModule instance = ((Class<? extends ICLIModule>) plugin).newInstance();
                modes.put(instance.getModeName(), instance.getClass());
            } catch (NoClassDefFoundError e) {
                e.printStackTrace();
                throw new Net2PlanException("Class " + e.getMessage() + " cannot be found. A dependence for "
                        + plugin.getSimpleName() + " is missing?");
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }

        Option helpOption = new Option("help", true,
                "Show the complete help information. 'modeName' is optional");
        helpOption.setArgName("modeName");
        helpOption.setOptionalArg(true);

        Option modeOption = new Option("mode", true,
                "Mode: " + StringUtils.join(StringUtils.toArray(modes.keySet()), ", "));
        modeOption.setArgName("modeName");
        modeOption.setOptionalArg(true);

        OptionGroup group = new OptionGroup();
        group.addOption(modeOption);
        group.addOption(helpOption);

        options.addOptionGroup(group);

        CommandLineParser parser = new CommandLineParser();
        CommandLine cli = parser.parse(options, args);

        if (cli.hasOption("help")) {
            String mode = cli.getOptionValue("help");
            System.out.println(mode == null ? getCompleteHelp() : getModeHelp(mode));
        } else if (!cli.hasOption("mode")) {
            System.out.println(getMainHelp());
        } else {
            String mode = cli.getOptionValue("mode");

            if (modes.containsKey(mode)) {
                ICLIModule modeInstance = modes.get(mode).newInstance();

                try {
                    modeInstance.executeFromCommandLine(args);
                } catch (Net2PlanException | JOMException ex) {
                    if (ErrorHandling.isDebugEnabled())
                        ErrorHandling.printStackTrace(ex);

                    System.out.println("Execution stopped");
                    System.out.println();
                    System.out.println(ex.getMessage());
                } catch (ParseException ex) {
                    System.out.println("Bad syntax: " + ex.getMessage());
                    System.out.println();
                    System.out.println(getModeHelp(mode));
                } catch (Throwable ex) {
                    Throwable ex1 = ErrorHandling.getInternalThrowable(ex);
                    if (ex1 instanceof Net2PlanException || ex1 instanceof JOMException) {
                        if (ErrorHandling.isDebugEnabled())
                            ErrorHandling.printStackTrace(ex);

                        System.out.println("Execution stopped");
                        System.out.println();
                        System.out.println(ex1.getMessage());
                    } else if (ex1 instanceof ParseException) {
                        System.out.println("Bad syntax: " + ex1.getMessage());
                        System.out.println();
                        System.out.println(getModeHelp(mode));
                    } else {
                        System.out.println("Execution stopped. An unexpected error happened");
                        System.out.println();
                        ErrorHandling.printStackTrace(ex1);
                    }
                }
            } else {
                throw new IllegalModeException("Bad mode - " + mode);
            }
        }
    } catch (IllegalModeException e) {
        System.out.println(e.getMessage());
        System.out.println();
        System.out.println(getMainHelp());
    } catch (ParseException e) {
        System.out.println("Bad syntax: " + e.getMessage());
        System.out.println();
        System.out.println(getMainHelp());
    } catch (Net2PlanException e) {
        if (ErrorHandling.isDebugEnabled())
            ErrorHandling.printStackTrace(e);
        System.out.println(e.getMessage());
    } catch (Throwable e) {
        ErrorHandling.printStackTrace(e);
    }
}

From source file:info.bitoo.Main.java

private static Options createCommandLineOptions() {
    Option optConfig = new Option("c", "config", true, "configuration file location");

    Option optTorrent = new Option("t", "torrent", true, "a .torrent file to download");
    optTorrent.setRequired(true);// w w w .  j a  va 2 s.  c  om

    Option optFile = new Option("f", "file", true, "a file to download on the specified tracker");
    optTorrent.setRequired(true);

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(optTorrent).addOption(optFile);

    Options cliOptions = new Options();
    cliOptions.addOption(optConfig);
    cliOptions.addOptionGroup(optionGroup);

    return cliOptions;
}

From source file:ditl.transfers.cli.AnalyzeTransfers.java

@Override
protected void initOptions() {
    super.initOptions();
    options.addOption(null, messagesOption, true, "name of messages trace");
    options.addOption(null, buffersOption, true, "name of buffer trace");
    options.addOption(null, transfersOption, true, "name of transfers trace");
    options.addOption(null, minTimeOption, true, "time to begin analysis");
    options.addOption(null, maxTimeOption, true, "time to end analysis");
    final OptionGroup reportGroup = new OptionGroup();
    reportGroup.addOption(new Option(null, broadcastDeliveryOption, false, "broadcast delivery report"));
    reportGroup.addOption(new Option(null, messageTransferOption, false, "message transfers report"));
    reportGroup.setRequired(true);/*  w w w. ja  va  2 s . c o m*/
    options.addOptionGroup(reportGroup);
}

From source file:com.toy.TOYConfig.java

private static final Options get() {
    Option tomcat = OptionBuilder.withArgName("tomcat").isRequired(false).hasArg()
            .withDescription("Tomcat home").create("tomcat");

    Option war = OptionBuilder.withArgName("war").isRequired(false).hasArg().withDescription("WAR file")
            .create("war");

    Option zookeeper = OptionBuilder.withArgName("zookeeper").isRequired().hasArg()
            .withDescription("zookeeper servers list e.g. : node1,node2,node3").create("zookeeper");

    Option queue = OptionBuilder.withArgName("queue").hasArg().withDescription("YARN queue (default : default)")
            .create("queue");

    Option maxmem = OptionBuilder.withArgName("memory").hasArg()
            .withDescription(// www. j  a v a 2 s . c o m
                    "Maximum memory allowed by the YARN container for the Tomcat instance (default : 64M)")
            .create("memory");

    Option ns = OptionBuilder.withArgName("namespace").hasArg()
            .withDescription("Deployment namespace (default : default)").create("namespace");

    Option log4j = OptionBuilder.withArgName("log4j").hasArg()
            .withDescription("Log4j configuration file, will be added to the Tomcat classpath").create("log4j");

    OptionGroup optionGroup = new OptionGroup();
    Option start = OptionBuilder.withArgName("start").hasArg(false)
            .withDescription("Start containers with given WAR").create("start");
    Option stop = OptionBuilder.withArgName("stop").hasArg().hasArg(false)
            .withDescription("Stop containers with given WAR").create("stop");
    Option status = OptionBuilder.withArgName("status").hasArg().hasArg(false)
            .withDescription("Give status about containers").create("status");
    Option add = OptionBuilder.withArgName("add").hasArg().hasArg(false).withDescription("Add new container")
            .create("add");

    optionGroup.addOption(start).addOption(stop).addOption(status).addOption(add).setRequired(true);

    return (new Options()).addOptionGroup(optionGroup).addOption(tomcat).addOption(zookeeper).addOption(war)
            .addOption(queue).addOption(maxmem).addOption(ns);
}