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

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

Introduction

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

Prototype

public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:com.alibaba.rocketmq.namesrv.NamesrvStartup.java

public static Options buildCommandlineOptions(final Options options) {
    Option opt = new Option("c", "configFile", true, "Name server config properties file");
    opt.setRequired(false);//from  w w w  .  j a  v a 2  s.co m
    options.addOption(opt);

    opt = new Option("p", "printConfigItem", false, "Print all config item");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}

From source file:esiptestbed.mudrod.ontology.process.LocalOntology.java

public static void main(String[] args) throws Exception {

    // boolean options
    Option helpOpt = new Option("h", "help", false, "show this help message");
    // argument options
    Option ontDirOpt = Option.builder(ONT_DIR).required(true).numberOfArgs(1).hasArg(true)
            .desc("A directory containing .owl files.").argName(ONT_DIR).build();

    // create the options
    Options options = new Options();
    options.addOption(helpOpt);/*from   ww w .  ja v  a 2  s.c o  m*/
    options.addOption(ontDirOpt);

    String ontDir;
    CommandLineParser parser = new DefaultParser();
    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption(ONT_DIR)) {
            ontDir = line.getOptionValue(ONT_DIR).replace("\\", "/");
        } else {
            ontDir = LocalOntology.class.getClassLoader().getResource("ontology").getFile();
        }
        if (!ontDir.endsWith("/")) {
            ontDir += "/";
        }
    } catch (Exception e) {
        LOG.error("Error whilst processing main method of LocalOntology.", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("LocalOntology: 'ontDir' argument is mandatory. ", options, true);
        return;
    }
    File fileDir = new File(ontDir);
    //Fail if the input is not a directory.
    if (fileDir.isDirectory()) {
        List<String> owlFiles = new ArrayList<>();
        for (File owlFile : fileDir.listFiles()) {
            owlFiles.add(owlFile.toString());
        }
        MudrodEngine mEngine = new MudrodEngine();
        Properties props = mEngine.loadConfig();
        Ontology ontology = new OntologyFactory(props).getOntology();
        //convert to correct iput for ontology loading.
        String[] owlArray = new String[owlFiles.size()];
        owlArray = owlFiles.toArray(owlArray);
        ontology.load(owlArray);

        String[] terms = new String[] { "Glacier ice" };
        //Demonstrate that we can do basic ontology heirarchy navigation and log output.
        for (Iterator<OntClass> i = getParser().rootClasses(getModel()); i.hasNext();) {

            //print Ontology Class Hierarchy
            OntClass c = i.next();
            renderHierarchy(System.out, c, new LinkedList<>(), 0);

            for (Iterator<OntClass> subClass = c.listSubClasses(true); subClass.hasNext();) {
                OntClass sub = subClass.next();
                //This means that the search term is present as an OntClass
                if (terms[0].equalsIgnoreCase(sub.getLabel(null))) {
                    //Add the search term(s) above to the term cache.
                    for (int j = 0; j < terms.length; j++) {
                        addSearchTerm(terms[j], sub);
                    }

                    //Query the ontology and return subclasses of the search term(s)
                    for (int k = 0; k < terms.length; k++) {
                        Iterator<String> iter = ontology.subclasses(terms[k]);
                        while (iter.hasNext()) {
                            LOG.info("Subclasses >> " + iter.next());
                        }
                    }

                    //print any synonymic relationships to demonstrate that we can 
                    //undertake synonym-based query expansion
                    for (int l = 0; l < terms.length; l++) {
                        Iterator<String> iter = ontology.synonyms(terms[l]);
                        while (iter.hasNext()) {
                            LOG.info("Synonym >> " + iter.next());
                        }
                    }
                }
            }
        }

        mEngine.end();
    }

}

From source file:com.opengamma.integration.tool.marketdata.MarketDataSnapshotToolUtils.java

public static Option createSnapshotListOption() {
    final Option option = new Option(SNAPSHOT_LIST_OPTION, "snapshot-list", false,
            "List the snapshots available");
    return option;
}

From source file:com.cloudbees.sdk.commands.CommandOption.java

public CommandOption(String opt, String longOpt, boolean hasArg, String description, boolean hidden) {
    if (longOpt != null)
        option = new Option(opt, longOpt, hasArg, description);
    else//from  w  w w. j a va  2 s . co m
        option = new Option(opt, hasArg, description);
    this.hidden = hidden;
}

From source file:com.fjn.helper.frameworkex.apache.commons.cli.Ls.java

@BeforeClass
public static void initOptions() {
    options.addOption("a", "all", false, "do not hide entries starting with .");
    options.addOption(new Option("A", "almost-all", false, "do not list implied . and .."));
    options.addOption("b", "escape", false, "print octal escapes for nongraphic " + "characters");
    options.addOption(Option.builder("").longOpt("block-size").desc("use SIZE-byte blocks").hasArg()
            .argName("SIZE").build());
    options.addOption("B", "ignore-backups", false, "do not list implied entried " + "ending with ~");
    options.addOption("c", false,
            "with -lt: sort by, and show, ctime (time of last "
                    + "modification of file status information) with "
                    + "-l:show ctime and sort by name otherwise: sort " + "by ctime");
    options.addOption("C", false, "list entries by columns");

}

From source file:com.zimbra.common.localconfig.LocalConfigUpgrade.java

private static Options getAllOptions() {
    Options options = new Options();
    options.addOption(O_HELP, "help", false, "print usage");
    options.addOption(O_CONFIG, "config", true, "path to localconfig.xml");
    options.addOption(O_TAG, "tag", true, "backup and tag with this suffix");
    Option bugOpt = new Option(O_BUG, "bug", true, "bug number this upgrade is for (multiple allowed)");
    bugOpt.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(bugOpt);/*from ww  w  .ja va2s  .c  o  m*/
    return options;
}

From source file:com.springrts.springls.CmdLineArgs.java

private static Options createOptions() {

    Configuration defaults = ServerConfiguration.getDefaults();

    Options options = new Options();

    Option help = new Option(null, "help", false, "Print this help message.");
    options.addOption(help);/* w w w  .j a  v  a2  s .c  om*/

    Option port = new Option("p", "port", true,
            String.format("The main (TCP) port number to host on [1, 65535]." + " The default is %d.",
                    defaults.getInt(ServerConfiguration.PORT)));
    // possible types:
    // * File.class
    // * Number.class
    // * Class.class
    // * Object.class
    // * Url.class
    port.setType(Number.class);
    port.setArgName("port-number");
    options.addOption(port);

    Option statistics = new Option(null, "statistics", false,
            "Whether to create and save statistics to disc on predefined" + " intervals.");
    options.addOption(statistics);

    Option natPort = new Option("n", "nat-port", true,
            String.format(
                    "The (UDP) port number to host the NAT traversal techniques"
                            + " help service on [1, 65535], which lets clients detect their"
                            + " source port, for example when using \"hole punching\"." + " The default is %d.",
                    defaults.getInt(ServerConfiguration.NAT_PORT)));
    port.setType(Number.class);
    natPort.setArgName("NAT-port-number");
    options.addOption(natPort);

    Option logMain = new Option(null, "log-main", false,
            String.format("Whether to log all conversations from channel #main to \"%s\"",
                    Channel.createDefaultActivityLogFilePath("main").getPath()));
    options.addOption(logMain);

    Option lanAdmin = new Option(null, "lan-admin", true,
            String.format(
                    "The LAN mode admin account. Use this account to administer"
                            + " your LAN server. The default is \"%s\", with password \"%s\".",
                    defaults.getString(ServerConfiguration.LAN_ADMIN_USERNAME),
                    defaults.getString(ServerConfiguration.LAN_ADMIN_PASSWORD)));
    lanAdmin.setArgName("username");
    options.addOption(lanAdmin);

    Option loadArgs = new Option(null, "load-args", true,
            "Will read command-line arguments from the specified file."
                    + " You can freely combine actual command-line arguments with"
                    + " the ones from the file. If duplicate args are specified,"
                    + " the last one will prevail.");
    loadArgs.setArgName("filename");
    port.setType(File.class);
    options.addOption(loadArgs);

    Option springVersion = new Option(null, "spring-version", true,
            "Will set the latest Spring version to this string."
                    + " The default is \"*\". This is used to tell clients which"
                    + " version is the latest one, so that they know when to" + " update.");
    springVersion.setArgName("version");
    options.addOption(springVersion);

    Option useStorageDb = new Option(null, "database", false,
            "Use a DB for user accounts and ban entries." + " This disables \"LAN mode\".");
    options.addOption(useStorageDb);

    Option useStorageFile = new Option(null, "file-storage", false,
            "Use the (deprecated) accounts.txt for user accounts." + " This disables \"LAN mode\".");
    options.addOption(useStorageFile);

    OptionGroup storageOG = new OptionGroup();
    storageOG.addOption(useStorageDb);
    storageOG.addOption(useStorageFile);
    options.addOptionGroup(storageOG);

    return options;
}

From source file:com.opengamma.integration.tool.marketdata.MarketDataSnapshotToolUtils.java

public static Option createSnapshotQueryOption() {
    final Option option = new Option(SNAPSHOT_QUERY_OPTION, "snapshot-query", true,
            "List the snapshots available according to a glob");
    option.setArgName("snapshot name glob");
    return option;
}

From source file:ch.ethz.topobench.graph.utility.CmdAssistant.java

/**
 * Add an option to the options.//  w  ww  .  j a  v  a2  s . co  m
 *
 * @param options   Options set for the command line
 * @param argShort  Short argument (-variant)
 * @param argLong   Long argument (-- variant)
 * @param required  Whether it is required
 * @param desc      Description
 */
public static void addOption(Options options, String argShort, String argLong, boolean required, String desc) {
    Option opt = new Option(argShort, argLong, true, desc);
    opt.setRequired(required);
    options.addOption(opt);
}

From source file:gov.nasa.jpl.mudrod.ontology.process.LocalOntology.java

public static void main(String[] args) throws Exception {

    // boolean options
    Option helpOpt = new Option("h", "help", false, "show this help message");
    // argument options
    Option ontDirOpt = OptionBuilder.hasArg(true).withArgName(ONT_DIR)
            .withDescription("A directory containing .owl files.").isRequired(false).create();

    // create the options
    Options options = new Options();
    options.addOption(helpOpt);/*w ww.j a  va  2  s.co  m*/
    options.addOption(ontDirOpt);

    String ontDir;
    CommandLineParser parser = new GnuParser();
    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption(ONT_DIR)) {
            ontDir = line.getOptionValue(ONT_DIR).replace("\\", "/");
        } else {
            ontDir = LocalOntology.class.getClassLoader().getResource("ontology").getFile();
        }
        if (!ontDir.endsWith("/")) {
            ontDir += "/";
        }
    } catch (Exception e) {
        LOG.error("Error whilst processing main method of LocalOntology.", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("LocalOntology: 'ontDir' argument is mandatory. ", options, true);
        return;
    }
    File fileDir = new File(ontDir);
    //Fail if the input is not a directory.
    if (fileDir.isDirectory()) {
        List<String> owlFiles = new ArrayList<>();
        for (File owlFile : fileDir.listFiles()) {
            owlFiles.add(owlFile.toString());
        }
        MudrodEngine mEngine = new MudrodEngine();
        Properties props = mEngine.loadConfig();
        Ontology ontology = new OntologyFactory(props).getOntology();
        //convert to correct iput for ontology loading.
        String[] owlArray = new String[owlFiles.size()];
        owlArray = owlFiles.toArray(owlArray);
        ontology.load(owlArray);

        String[] terms = new String[] { "Glacier ice" };
        //Demonstrate that we can do basic ontology heirarchy navigation and log output.
        for (Iterator<OntClass> i = getParser().rootClasses(getModel()); i.hasNext();) {

            //print Ontology Class Hierarchy
            OntClass c = i.next();
            renderHierarchy(System.out, c, new LinkedList<>(), 0);

            for (Iterator<OntClass> subClass = c.listSubClasses(true); subClass.hasNext();) {
                OntClass sub = subClass.next();
                //This means that the search term is present as an OntClass
                if (terms[0].equalsIgnoreCase(sub.getLabel(null))) {
                    //Add the search term(s) above to the term cache.
                    for (int j = 0; j < terms.length; j++) {
                        addSearchTerm(terms[j], sub);
                    }

                    //Query the ontology and return subclasses of the search term(s)
                    for (int k = 0; k < terms.length; k++) {
                        Iterator<String> iter = ontology.subclasses(terms[k]);
                        while (iter.hasNext()) {
                            LOG.info("Subclasses >> " + iter.next());
                        }
                    }

                    //print any synonymic relationships to demonstrate that we can 
                    //undertake synonym-based query expansion
                    for (int l = 0; l < terms.length; l++) {
                        Iterator<String> iter = ontology.synonyms(terms[l]);
                        while (iter.hasNext()) {
                            LOG.info("Synonym >> " + iter.next());
                        }
                    }
                }
            }
        }

        mEngine.end();
    }

}