Package org.apache.commons.cli

Examples of org.apache.commons.cli.Option


        ArrayList list = new ArrayList();

        StringBuffer optionsBuff = new StringBuffer();
       
        // temp variable
        Option option;

        // iterate over the options
        for (Iterator i = options.getOptions().iterator(); i.hasNext();) {
            // get the next Option
            option = (Option) i.next();

            // check if the option is part of an OptionGroup
            OptionGroup group = options.getOptionGroup(option);

            // if the option is part of a group and the group has not already
            // been processed
            if (group != null && !list.contains(group)) {

                // add the group to the processed list
                list.add(group);

                // get the names of the options from the OptionGroup
                Collection names = group.getNames();

                optionsBuff.append("[");

                // for each option in the OptionGroup
                for (Iterator iter = names.iterator(); iter.hasNext();) {
                    optionsBuff.append(iter.next());
                    if (iter.hasNext()) {
                        optionsBuff.append("|");
                    }
                }
                optionsBuff.append("] ");
            } else if (group == null) {
                // if the Option is not part of an OptionGroup
                // if the Option is not a required option
                if (!option.isRequired()) {
                    optionsBuff.append("[");
                }

                if (!" ".equals(option.getOpt())) {
                    optionsBuff.append("-").append(option.getOpt());
                } else {
                    optionsBuff.append("--").append(option.getLongOpt());
                }

                if (option.hasArg()) {
                    optionsBuff.append(" ");
                }

                // if the Option has a value
                if (option.hasArg()) {
                    optionsBuff.append(option.getArgName());
                }

                // if the Option is not a required option
                if (!option.isRequired()) {
                    optionsBuff.append("]");
                }
                optionsBuff.append(" ");
            }
        }
View Full Code Here


        //long opt; in parallel look for the longest opt string
        //this list will be then used to sort options ascending
        int max = 0;
        StringBuffer optBuf;
        List prefixList = new ArrayList();
        Option option;
        List optList = new ArrayList(options.getOptions());
        Collections.sort(optList, new StringBufferComparator());
        for (Iterator i = optList.iterator(); i.hasNext();) {
            option = (Option) i.next();
            optBuf = new StringBuffer(8);

            if (option.getOpt().equals(" ")) {
                optBuf.append(lpad).append("   " + defaultLongOptPrefix).append(option.getLongOpt());
            } else {
                optBuf.append(lpad).append(defaultOptPrefix).append(option.getOpt());
                if (option.hasLongOpt()) {
                    optBuf.append(',').append(defaultLongOptPrefix).append(option.getLongOpt());
                }

            }

            if (option.hasArg()) {
                if (option.hasArgName()) {
                    optBuf.append(" <").append(option.getArgName()).append('>');
                } else {
                    optBuf.append(' ');
                }
            }

            prefixList.add(optBuf);
            max = optBuf.length() > max ? optBuf.length() : max;
        }
        int x = 0;
        for (Iterator i = optList.iterator(); i.hasNext();) {
            option = (Option) i.next();
            optBuf = new StringBuffer(prefixList.get(x++).toString());

            if (optBuf.length() < max) {
                optBuf.append(createPadding(max - optBuf.length()));
            }
            optBuf.append(dpad);
           
            if (displayDesc) {
                optBuf.append(option.getDescription());
            }
            int nextLineTabStop = max + descPad;
            renderWrappedText(sb, width, nextLineTabStop, optBuf.toString());
            if (i.hasNext()) {
                sb.append(defaultNewLine);
View Full Code Here

    protected void addOptionWithParam(String longOption, String shortOption, String argName, String desc) {
        OptionBuilder optionBuilder = OptionBuilder.hasArg().withArgName(argName);
        optionBuilder = optionBuilder.withLongOpt(longOption);
        optionBuilder = optionBuilder.withDescription(desc);
        Option option = optionBuilder.create(shortOption);
        options.addOption(option);
    }
View Full Code Here

    }

    private static Options buildOptions() {
        Options opts = new Options();

        Option help = new Option("h", "help", false,
        "Print help for the Rat command line interface and exit");
        opts.addOption(help);

        OptionGroup addLicenceGroup = new OptionGroup();
        String addLicenceDesc = "Add the default licence header to any file with an unknown licence that is not in the exclusion list. By default new files will be created with the licence header, to force the modification of existing files use the --force option.";

        Option addLicence = new Option(
                "a",
                "addLicence",
                false,
                addLicenceDesc);
        addLicenceGroup.addOption(addLicence);
        Option addLicense = new Option(
                "A",
                "addLicense",
                false,
                addLicenceDesc);
        addLicenceGroup.addOption(addLicense);
        opts.addOptionGroup(addLicenceGroup);

        Option write = new Option(
                "f",
                "force",
                false,
        "Forces any changes in files to be written directly to the source files (i.e. new files are not created)");
        opts.addOption(write);

        Option copyright = new Option(
                "c",
                "copyright",
                true,
        "The copyright message to use in the licence headers, usually in the form of \"Copyright 2008 Foo\"");
        opts.addOption(copyright);

        final Option exclude = OptionBuilder
                            .withArgName("expression")
                            .withLongOpt("exclude")
                            .hasArgs()
                            .withDescription("Excludes files matching wildcard <expression>. " +
                                    "Note that --dir is required when using this parameter. " +
                                    "Allows multiple arguments.")
                            .create(EXCLUDE_CLI);
        opts.addOption(exclude);

        final Option excludeFile = OptionBuilder
                            .withArgName("fileName")
                            .withLongOpt("exclude-file")
                            .hasArgs()
                            .withDescription("Excludes files matching regular expression in <file> " +
                                    "Note that --dir is required when using this parameter. " )
                            .create(EXCLUDE_FILE_CLI);
        opts.addOption(excludeFile);

        Option dir = new Option(
                "d",
                "dir",
                false,
        "Used to indicate source when using --exclude");
        opts.addOption(dir);

        OptionGroup outputType = new OptionGroup();

        Option xml = new Option(
                "x",
                "xml",
                false,
                "Output the report in raw XML format.  Not compatible with -s");
        outputType.addOption(xml);

        Option xslt = new Option(String.valueOf(STYLESHEET_CLI),
                                 "stylesheet",
                                 true,
                                 "XSLT stylesheet to use when creating the"
                                 + " report.  Not compatible with -x");
        outputType.addOption(xslt);
View Full Code Here

    return result;
  }

  @SuppressWarnings("static-access")
  private static Options constructCommandLineOptions() {
    Option helpOption =
        OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();

    Option zkServerOption =
        OptionBuilder.withLongOpt(zkServerAddress).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option clusterOption =
        OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option timeoutOption =
        OptionBuilder.withLongOpt(timeout).withDescription("Timeout value for verification")
            .create();
    timeoutOption.setArgs(1);
    timeoutOption.setArgName("Timeout value (Optional), default=30s");

    Option sleepIntervalOption =
        OptionBuilder.withLongOpt(period).withDescription("Polling period for verification")
            .create();
    sleepIntervalOption.setArgs(1);
    sleepIntervalOption.setArgName("Polling period value (Optional), default=1s");

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOption(clusterOption);
View Full Code Here

    setOptions();
  }

  private void setOptions() {
    options.addOption("h", "help", false, "Help");
    options.addOption(new Option("check", false, "Run upgrade check; looks for HFileV1 "
        + " under ${hbase.rootdir} or provided 'dir' directory."));
    options.addOption(new Option("execute", false, "Run upgrade; zk and hdfs must be up, hbase down"));
    Option pathOption = new Option("dir", true,
        "Relative path of dir to check for HFileV1s.");
    pathOption.setRequired(false);
    options.addOption(pathOption);
  }
View Full Code Here

        Options options = new Options();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine line = null;

        {
            Option opt = new Option("t", "test", false, "Run test session");
            opt.setRequired(false);
            options.addOption(opt);
        }

        {
            Option opt = new Option("h", "help", false,
                    "Print this help message");
            opt.setRequired(false);
            options.addOption(opt);
        }

        try
        {
View Full Code Here

        Options options = new Options();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine line = null;

        {
            Option opt = new Option("m", "mode", true,
                    "mode (1: daily, 7: weekly, 30: monthly)");
            opt.setRequired(true);
            options.addOption(opt);
        }

        {
            Option opt = new Option("t", "test", false, "Run test session");
            opt.setRequired(false);
            options.addOption(opt);
        }

        {
            Option opt = new Option("h", "help", false,
                    "Print this help message");
            opt.setRequired(false);
            options.addOption(opt);
        }

        try
        {
View Full Code Here

    options.addOption("r",false,"process directories recursively when -i is a directory ");
    options.addOption("o",true, "output file");
    options.addOption("h",false,"print this message");
    options.addOption("v",false,"print version information");
    OptionGroup outputOptions = new OptionGroup();
    Option stdxml = new Option("x",false,"convert FITS output to a standard metadata schema");
    Option combinedStd = new Option("xc",false,"output using a standard metadata schema and include FITS xml");
    outputOptions.addOption(stdxml);
    outputOptions.addOption(combinedStd);
    options.addOptionGroup(outputOptions);

    CommandLineParser parser = new GnuParser();
View Full Code Here

    public OozieDBCLI() {
        used = false;
    }

    protected Options createUpgradeOptions() {
        Option sqlfile = new Option(SQL_FILE_OPT, true, "Generate SQL script instead creating/upgrading the DB schema");
        Option run = new Option(RUN_OPT, false, "Confirm the DB schema creation/upgrade");
        Options options = new Options();
        options.addOption(sqlfile);
        options.addOption(run);
        return options;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.cli.Option

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.