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:net.sourceforge.metware.binche.execs.BiNCheExec.java

@Override
public void setupOptions() {

    add(new Option("g", "true", false, "run graphical user interface"));
    add(new Option("i", "file to load", true, "association file to load"));
    add(new Option("o", "output directory", true, "directory to write output to"));
}

From source file:com.graphaware.importer.cli.FileCommandLineParser.java

/**
 * {@inheritDoc}/*from ww w  .j av  a 2 s. c o  m*/
 */
@Override
protected void addOptions(Options options) {
    options.addOption(new Option("i", "input", true, "use given directory to find input files"));
}

From source file:de.tudarmstadt.lt.lm.app.SentPerp.java

/**
 * //  w  w w. ja v a 2  s  .  c  o  m
 */
@SuppressWarnings("static-access")
public SentPerp(String args[]) {
    Options opts = new Options();

    opts.addOption(new Option("?", "help", false, "display this message"));
    opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg()
            .withDescription(
                    String.format("Specifies the port on which the rmi registry listens (default: %d).",
                            Registry.REGISTRY_PORT))
            .create("p"));
    opts.addOption(OptionBuilder.withLongOpt("selftest")
            .withDescription("Run a selftest, compute perplexity of ngrams in specified LM.").create("s"));
    opts.addOption(OptionBuilder.withLongOpt("quiet").withDescription("Run with minimum outout on stdout.")
            .create("q"));
    opts.addOption(OptionBuilder.withLongOpt("noov").hasOptionalArg().withArgName("{true|false}")
            .withDescription("Do not consider oov terms, i.e. ngrams that end in an oov term. (default: false)")
            .create());
    opts.addOption(OptionBuilder.withLongOpt("oovreflm").withArgName("identifier").hasArg().withDescription(
            "Do not consider oov terms with respect to the provided lm, i.e. ngrams that end in an oov term in the referenced lm. (default use current lm)")
            .create());
    opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg()
            .withDescription("Specifies the hostname on which the rmi registry listens (default: localhost).")
            .create("h"));
    opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription(
            "Specify the file or directory that contains '.txt' files that are used as source for testing perplexity with the specified language model. Specify '-' to pipe from stdin. (default: '-').")
            .create("f"));
    opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg()
            .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').")
            .create("o"));
    opts.addOption(OptionBuilder.withLongOpt("name").withArgName("identifier").isRequired().hasArg()
            .withDescription("Specify the name of the language model provider that you want to connect to.")
            .create("i"));

    try {
        CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args);
        if (cmd.hasOption("help"))
            CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0);

        _host = cmd.getOptionValue("host", "localhost");
        _rmiport = Integer.parseInt(cmd.getOptionValue("port", String.valueOf(Registry.REGISTRY_PORT)));
        _file = cmd.getOptionValue("file", "-");
        _out = cmd.getOptionValue("out", "-");
        _name = cmd.getOptionValue("name");
        _host = cmd.getOptionValue("host", "localhost");
        _selftest = cmd.hasOption("selftest");
        _quiet = cmd.hasOption("quiet");
        _no_oov = cmd.hasOption("noov");
        if (_no_oov && cmd.getOptionValue("noov") != null)
            _no_oov = Boolean.parseBoolean(cmd.getOptionValue("noov"));
        _oovreflm_name = cmd.getOptionValue("oovreflm");

    } catch (Exception e) {
        LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage());
        CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER,
                String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1);
    }
    _rmi_string = String.format("rmi://%s:%d/%s", _host, _rmiport, _name);
}

From source file:com.cyberway.issue.crawler.CommandLineParser.java

/**
 * Constructor./*from   w  w w . j av  a  2s . co  m*/
 *
 * @param args Command-line arguments to process.
 * @param out PrintStream to write on.
 * @param version Heritrix version
 *
 * @throws ParseException Failied parse of command line.
 */
public CommandLineParser(String[] args, PrintWriter out, String version) throws ParseException {
    super();

    this.out = out;
    this.version = version;

    this.options = new Options();
    this.options.addOption(new Option("h", "help", false, "Prints this message and exits."));
    this.options.addOption(new Option("b", "bind", true,
            "Comma-separated list of IP addresses or hostnames for web server "
                    + "to listen on.  Set to / to listen on all available\nnetwork "
                    + "interfaces.  Default is 127.0.0.1."));
    this.options.addOption(new Option("p", "port", true, "Port to run web user interface on.  Default: 8080."));
    this.options.addOption(new Option("a", "admin", true,
            "Login and password for web user interface administration. "
                    + "Required (unless passed via the 'heritrix.cmdline.admin'\n"
                    + "system property).  Pass value of the form 'LOGIN:PASSWORD'."));
    this.options
            .addOption(new Option("r", "run", false, "Put heritrix into run mode. If ORDER.XML begin crawl."));
    this.options.addOption(
            new Option("n", "nowui", false, "Put heritrix into run mode and begin crawl using ORDER.XML."
                    + " Do not put up web user interface."));
    Option option = new Option("s", "selftest", true,
            "Run the integrated selftests. Pass test name to test it only"
                    + " (Case sensitive: E.g. pass 'Charset' to run charset selftest).");
    option.setOptionalArg(true);
    this.options.addOption(option);

    PosixParser parser = new PosixParser();
    try {
        this.commandLine = parser.parse(this.options, args, false);
    } catch (UnrecognizedOptionException e) {
        usage(e.getMessage(), 1);
    }
}

From source file:android.example.hlsmerge.crypto.Main.java

private static CommandLine parseCommandLine(String[] args) {
    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;//www .  j  a  v  a  2  s.  c o  m

    Option help = new Option(OPT_HELP, "help", false, "print this message.");
    Option silent = new Option(OPT_SILENT, "silent", false, "silent mode.");
    Option overwrite = new Option(OPT_OVERWRITE, false, "overwrite output files.");

    Option key = OptionBuilder.withArgName(ARG_KEY).withLongOpt(OPT_KEY_LONG).hasArg()
            .withDescription("force use of the supplied AES-128 key.").create(OPT_KEY);

    Option outFile = OptionBuilder.withArgName(ARG_OUT_FILE).withLongOpt(OPT_OUT_FILE_LONG).hasArg()
            .withDescription("join all transport streams to one file.").create(OPT_OUT_FILE);

    Options options = new Options();

    options.addOption(help);
    options.addOption(silent);
    options.addOption(overwrite);
    options.addOption(key);
    options.addOption(outFile);

    try {
        commandLine = parser.parse(options, args);

        if (commandLine.hasOption(OPT_HELP) || (commandLine.getArgs().length < 1)) {
            new HelpFormatter().printHelp(CLI_SYNTAX, options);
            System.exit(0);
        }

        if (commandLine.hasOption(OPT_KEY)) {
            String optKey = commandLine.getOptionValue(OPT_KEY);

            if (!optKey.matches("[0-9a-fA-F]{32}")) {
                System.out.printf(
                        "Bad key format: \"%s\". Expected 32-character hex format.\nExample: -key 12ba7f70db4740dec4aab4c5c2c768d9",
                        optKey);
                System.exit(1);
            }
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        new HelpFormatter().printHelp(CLI_SYNTAX, options);
        System.exit(1);
    }

    return commandLine;
}

From source file:com.twitter.hraven.etl.JobFileRawLoader.java

/**
 * Parse command-line arguments.//from   w  w w  . ja  va 2s .com
 * 
 * @param args
 *          command line arguments passed to program.
 * @return parsed command line.
 * @throws ParseException
 */
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    // Cluster
    Option o = new Option("c", "cluster", true, "cluster for which jobs are processed");
    o.setArgName("cluster");
    o.setRequired(true);
    options.addOption(o);

    o = new Option("p", "processFileSubstring", true,
            "use only those process records where the process file path contains the provided string. Useful when processing production jobs in parallel to historic loads.");
    o.setArgName("processFileSubstring");
    o.setRequired(false);
    options.addOption(o);

    // Force
    o = new Option("f", "forceReprocess", false,
            "Force all jobs for which a jobFile is loaded to be reprocessed. Optional. Default is false.");
    o.setRequired(false);
    options.addOption(o);

    // Debugging
    options.addOption("d", "debug", false, "switch on DEBUG log level");

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println("ERROR: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NAME + " ", options, true);
        System.exit(-1);
    }

    // Set debug level right away
    if (commandLine.hasOption("d")) {
        Logger log = Logger.getLogger(JobFileRawLoader.class);
        log.setLevel(Level.DEBUG);
    }

    return commandLine;
}

From source file:Dcm2Txt.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();
    Option width = new Option("w", "width", true, "maximal number of characters per line, by default: 80");
    width.setArgName("max");
    opts.addOption(width);//w  w w . j ava 2 s .co  m
    Option vallen = new Option("l", "vallen", true,
            "limit value prompt to <maxlen> characters, by default: 64");
    vallen.setArgName("max");
    opts.addOption(vallen);
    opts.addOption("c", "compact", false, "dump without attribute names");
    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new PosixParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcm2txt: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Dcm2Txt.class.getPackage();
        System.out.println("dcm2txt v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().isEmpty()) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    return cl;
}

From source file:fr.inria.edelweiss.kgimport.RdfSplitter.java

/**
 * The application entrypoint, configured through the command line input
 * arguments./* w w  w .j  av a2 s.co m*/
 *
 * @param args the input command line arguments.
 */
public static void main(String args[]) {

    RdfSplitter rdfSplitter = new RdfSplitter();

    Options options = new Options();
    Option helpOpt = new Option("h", "help", false, "Print usage information.");
    Option inDirOpt = new Option("i", "input-dir", true, "The directory containing RDF files to be loaded.");
    Option outDirOpt = new Option("o", "output-dir", true,
            "The directory containing the generated RDF fragments");
    Option predFiltOpt = new Option("p", "predicate-filter", true,
            "Predicate filter used to segment the dataset. "
                    + "You can use multiple filters, typically one per fragment.");
    Option fragNbOpt = new Option("n", "number-of-fragments", true,
            "Number of fragments generated for the whole input dataset.");
    Option fragRepOpt = new Option("f", "fractionning-percentage", true,
            "Percentage of the whole input dataset for this fragment.");
    Option tdbOpt = new Option("tdb", "tdb-storage", false,
            "RDF fragments are persisted into a Jena TDB backend.");
    Option versionOpt = new Option("v", "version", false, "Print the version information and exit.");
    options.addOption(inDirOpt);
    options.addOption(outDirOpt);
    options.addOption(predFiltOpt);
    options.addOption(helpOpt);
    options.addOption(versionOpt);
    options.addOption(fragNbOpt);
    options.addOption(fragRepOpt);
    options.addOption(tdbOpt);

    String header = "RDF data fragmentation tool command line interface";
    String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr";

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar [].jar", header, options, footer, true);
            System.exit(0);
        }

        if (!cmd.hasOption("i")) {
            logger.warn("You must specify a valid input directory !");
            System.exit(-1);
        } else {
            rdfSplitter.setInputDirPath(cmd.getOptionValue("i"));
        }
        if (!cmd.hasOption("o")) {
            logger.warn("You must specify a valid output directory !");
            System.exit(-1);
        } else {
            rdfSplitter.setOutputDirPath(cmd.getOptionValue("o"));
        }
        if (cmd.hasOption("p")) {
            rdfSplitter.setInputPredicates(new ArrayList<String>(Arrays.asList(cmd.getOptionValues("p"))));
        }
        if (cmd.hasOption("f")) {
            ArrayList<String> opts = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("f")));
            for (String opt : opts) {
                try {
                    rdfSplitter.getFragList().add(Integer.parseInt(opt));
                } catch (NumberFormatException e) {
                    logger.error(opt + " cannot be pased as an percentage value.");
                    System.exit(-1);
                }
            }
        }
        if (cmd.hasOption("n")) {
            try {
                rdfSplitter.setFragNb(Integer.parseInt(cmd.getOptionValue("n")));
            } catch (NumberFormatException e) {
                logger.error(cmd.getOptionValue("n") + " cannot be pased as an integer value.");
                System.exit(-1);
            }
        }

        File oDir = new File(rdfSplitter.getOutputDirPath());
        if (oDir.exists()) {
            logger.warn(rdfSplitter.getOutputDirPath() + " already exists !");
            oDir = Files.createTempDir();
            logger.warn(oDir.getAbsolutePath() + " created.");
            rdfSplitter.setOutputDirPath(oDir.getAbsolutePath());
        } else {
            if (oDir.mkdir()) {
                logger.info(rdfSplitter.getOutputDirPath() + " created.");
            }
        }

        if (!cmd.hasOption("n") && !cmd.hasOption("f") && !cmd.hasOption("p")) {
            logger.error("You must specify just one fragmentation type through '-n', '-f', or 'p' options");
            for (String arg : args) {
                logger.trace(arg);
            }
            System.exit(-1);
        }

        String fragName = rdfSplitter.getInputDirPath()
                .substring(rdfSplitter.getInputDirPath().lastIndexOf("/") + 1);

        //Input data loading
        Model model = ModelFactory.createDefaultModel();
        File inputDir = new File(rdfSplitter.getInputDirPath());
        if (inputDir.isDirectory()) {
            for (File f : inputDir.listFiles()) {
                logger.info("Loading " + f.getAbsolutePath());
                if (f.isDirectory()) {
                    String directory = f.getAbsolutePath();
                    Dataset dataset = TDBFactory.createDataset(directory);
                    dataset.begin(ReadWrite.READ);
                    // Get model inside the transaction
                    model.add(dataset.getDefaultModel());
                    dataset.end();
                } else {
                    InputStream iS;
                    try {
                        iS = new FileInputStream(f);
                        if (f.getAbsolutePath().endsWith(".n3")) {
                            model.read(iS, null, "N3");
                        } else if (f.getAbsolutePath().endsWith(".nt")) {
                            model.read(iS, null, "N-TRIPLES");
                        } else if (f.getAbsolutePath().endsWith(".rdf")) {
                            model.read(iS, null);
                        }
                    } catch (FileNotFoundException ex) {
                        LogManager.getLogger(RdfSplitter.class.getName()).log(Level.ERROR, "", ex);
                    }
                }
            }
            logger.info("Loaded " + model.size() + " triples");
        } else {
            System.exit(0);
        }

        StopWatch sw = new StopWatch();
        if (cmd.hasOption("n")) {
            sw.start();
            if (cmd.hasOption("tdb")) {
                rdfSplitter.saveFragmentsTDB(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragNb()),
                        "Homog-" + fragName);
            } else {
                rdfSplitter.saveFragmentsRDF(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragNb()),
                        "Homog-" + fragName);
            }
            logger.info("Homog horiz frag in " + sw.getTime() + "ms");
            sw.reset();
        } else if (cmd.hasOption("f")) {
            sw.start();
            if (cmd.hasOption("tdb")) {
                rdfSplitter.saveFragmentsTDB(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragList()),
                        "Inhomog-" + fragName);
            } else {
                rdfSplitter.saveFragmentsRDF(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragList()),
                        "Inhomog-" + fragName);
            }
            logger.info("Inhomog horiz frag in " + sw.getTime() + "ms");
            sw.reset();
        } else if (cmd.hasOption("p")) {
            sw.start();
            if (cmd.hasOption("tdb")) {
                rdfSplitter.saveFragmentsTDB(rdfSplitter.getFragVert(model, rdfSplitter.getInputPredicates()));
            } else {
                rdfSplitter.saveFragmentsRDF(rdfSplitter.getFragVert(model, rdfSplitter.getInputPredicates()));
            }
            logger.info("Vert frag in " + sw.getTime() + "ms");
            sw.reset();
        }

    } catch (ParseException ex) {
        logger.error("Impossible to parse the input command line " + cmd.toString());
    }
}

From source file:io.github.discovermovies.datacollector.movie.Application.java

private Options getOptions() {
    Options options = new Options();

    //Boolean options
    Option version = new Option("v", "version", false, "Output the version and exit");
    Option help = new Option("h", "help", false, "Show help");

    //Arguement options
    Option credentials = Option.builder("u").numberOfArgs(2).argName("Username and password")
            .desc("Username followed by password").build();

    Option databse = Option.builder("d").hasArg().argName("Host URL")
            .desc("URL of Mysql server host if it is not localhost").build();

    options.addOption(databse);/* www  . j a v  a  2 s  . c  o m*/
    options.addOption(credentials);
    options.addOption(help);
    options.addOption(version);

    return options;
}

From source file:com.buildml.main.commands.CliCommandAddPkg.java

@Override
public Options getOptions() {

    Options opts = new Options();

    /* add the --folder option */
    Option addFolderOpt = new Option("f", "folder", false, "Create a folder.");
    opts.addOption(addFolderOpt);//from   w w w.  ja v a  2  s  .  c o  m

    return opts;
}