Example usage for java.lang IllegalArgumentException IllegalArgumentException

List of usage examples for java.lang IllegalArgumentException IllegalArgumentException

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException IllegalArgumentException.

Prototype

public IllegalArgumentException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.tamingtext.classifier.maxent.TestMaxent.java

/**
 * @param args/*from   w  w w . ja  v a 2 s . c om*/
 */
public static void main(String[] args) throws IOException {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option helpOpt = DefaultOptionCreator.helpOption();

    Option inputDirOpt = obuilder.withLongName("input").withRequired(true)
            .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create())
            .withDescription("The input directory").withShortName("i").create();

    Option modelOpt = obuilder.withLongName("model").withRequired(true)
            .withArgument(abuilder.withName("index").withMinimum(1).withMaximum(1).create())
            .withDescription("The directory containing the index model").withShortName("m").create();

    Group group = gbuilder.withName("Options").withOption(helpOpt).withOption(inputDirOpt).withOption(modelOpt)
            .create();

    try {
        Parser parser = new Parser();

        parser.setGroup(group);
        parser.setHelpOption(helpOpt);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        String inputPath = (String) cmdLine.getValue(inputDirOpt);
        File f = new File(inputPath);
        if (!f.isDirectory()) {
            throw new IllegalArgumentException(f + " is not a directory or does not exit");
        }
        File[] inputFiles = FileUtil.buildFileList(f);

        File modelDir = new File((String) cmdLine.getValue(modelOpt));
        execute(inputFiles, modelDir);
    } catch (OptionException e) {
        log.error("Error while parsing options", e);
    }

}

From source file:com.leshazlewood.scms.cli.Main.java

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

    CommandLineParser parser = new PosixParser();

    Options options = new Options();
    options.addOption(CONFIG).addOption(DEBUG).addOption(HELP).addOption(VERSION);

    boolean debug = false;
    File sourceDir = toFile(System.getProperty("user.dir"));
    File configFile = null;//from   w  ww. ja  v  a2  s  . c om
    File destDir = null;

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

        if (line.hasOption(VERSION.getOpt())) {
            printVersionAndExit();
        }
        if (line.hasOption(HELP.getOpt())) {
            printHelpAndExit(options, null, debug, 0);
        }
        if (line.hasOption(DEBUG.getOpt())) {
            debug = true;
        }
        if (line.hasOption(CONFIG.getOpt())) {
            String configFilePath = line.getOptionValue(CONFIG.getOpt());
            configFile = toFile(configFilePath);
        }

        String[] remainingArgs = line.getArgs();
        if (remainingArgs == null) {
            printHelpAndExit(options, null, debug, -1);
        }

        assert remainingArgs != null;

        if (remainingArgs.length == 1) {
            String workingDirPath = System.getProperty("user.dir");
            sourceDir = toFile(workingDirPath);
            destDir = toFile(remainingArgs[0]);
        } else if (remainingArgs.length == 2) {
            sourceDir = toFile(remainingArgs[0]);
            destDir = toFile((remainingArgs[1]));
        } else {
            printHelpAndExit(options, null, debug, -1);
        }

        assert sourceDir != null;
        assert destDir != null;

        if (configFile == null) {
            configFile = new File(sourceDir, DEFAULT_CONFIG_FILE_NAME);
        }

        if (configFile.exists()) {
            if (configFile.isDirectory()) {
                throw new IllegalArgumentException(
                        "Expected configuration file " + configFile + " is a directory, not a file.");
            }
        } else {
            String msg = "Configuration file not found.  Create a default " + DEFAULT_CONFIG_FILE_NAME
                    + " file in your source directory or specify the " + CONFIG
                    + " option to provide the file location.";
            throw new IllegalStateException(msg);
        }

        SiteExporter siteExporter = new SiteExporter();
        siteExporter.setSourceDir(sourceDir);
        siteExporter.setDestDir(destDir);
        siteExporter.setConfigFile(configFile);
        siteExporter.init();
        siteExporter.execute();

    } catch (IllegalArgumentException iae) {
        exit(iae, debug);
    } catch (IllegalStateException ise) {
        exit(ise, debug);
    } catch (Exception e) {
        printHelpAndExit(options, e, debug, -1);
    }
}

From source file:com.ecyrd.jspwiki.util.CryptoUtil.java

/**
 * <p>//from ww w.  j  a  v  a2  s .c om
 * Convenience method for hashing and verifying salted SHA-1 passwords from
 * the command line. This method requires <code>commons-codec-1.3.jar</code>
 * (or a newer version) to be on the classpath. Command line arguments are
 * as follows:
 * </p>
 * <ul>
 * <li><code>--hash <var>password</var></code> - hashes <var>password</var></code>
 * and prints a password digest that looks like this: <blockquote><code>{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=</code></blockquote></li>
 * <li><code>--verify <var>password</var> <var>digest</var></code> -
 * verifies <var>password</var> by extracting the salt from <var>digest</var>
 * (which is identical to what is printed by <code>--hash</code>) and
 * re-computing the digest again using the password and salt. If the
 * password supplied is the same as the one used to create the original
 * digest, <code>true</code> will be printed; otherwise <code>false</code></li>
 * </ul>
 * <p>For example, one way to use this utility is to change to JSPWiki's <code>build</code> directory
 * and type the following command:</p>
 * <blockquote><code>java -cp JSPWiki.jar:../lib/commons-codec-1.3.jar com.ecyrd.jspwiki.util.CryptoUtil --hash mynewpassword</code></blockquote>
 * 
 * @param args arguments for this method as described above
 * @throws Exception Catches nothing; throws everything up.
 */
public static void main(final String[] args) throws Exception {
    // Print help if the user requested it, or if no arguments
    if (args.length == 0 || (args.length == 1 && HELP.equals(args[0]))) {
        System.out.println("Usage: CryptUtil [options] ");
        System.out.println("   --hash   password             create hash for password");
        System.out.println("   --verify password digest      verify password for digest");
        System.exit(0);
    }

    // User wants to hash the password
    if (HASH.equals(args[0])) {
        if (args.length < 2) {
            throw new IllegalArgumentException("Error: --hash requires a 'password' argument.");
        }
        final String password = args[1].trim();
        System.out.println(CryptoUtil.getSaltedPassword(password.getBytes("UTF-8")));
    }

    // User wants to verify an existing password
    else if (VERIFY.equals(args[0])) {
        if (args.length < 3) {
            throw new IllegalArgumentException("Error: --hash requires 'password' and 'digest' arguments.");
        }
        final String password = args[1].trim();
        final String digest = args[2].trim();
        System.out.println(CryptoUtil.verifySaltedPassword(password.getBytes("UTF-8"), digest));
    }

    else {
        System.out.println("Wrong usage. Try --help.");
    }
}

From source file:com._37coins.CryptoUtils.java

/**
 * <p>/*w  ww.  j a  v a 2  s .  co m*/
 * Convenience method for hashing and verifying salted SHA-1 passwords from
 * the command line. This method requires <code>commons-codec-1.3.jar</code>
 * (or a newer version) to be on the classpath. Command line arguments are
 * as follows:
 * </p>
 * <ul>
 * <li><code>--hash <var>password</var></code> - hashes
 * <var>password</var></code> and prints a password digest that looks like
 * this: <blockquote><code>{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=</code>
 * </blockquote></li>
 * <li><code>--verify <var>password</var> <var>digest</var></code> -
 * verifies <var>password</var> by extracting the salt from
 * <var>digest</var> (which is identical to what is printed by
 * <code>--hash</code>) and re-computing the digest again using the password
 * and salt. If the password supplied is the same as the one used to create
 * the original digest, <code>true</code> will be printed; otherwise
 * <code>false</code></li>
 * </ul>
 * <p>
 * For example, one way to use this utility is to change to JSPWiki's
 * <code>build</code> directory and type the following command:
 * </p>
 * <blockquote>
 * <code>java -cp JSPWiki.jar:../lib/commons-codec-1.3.jar com.ecyrd.jspwiki.util.CryptoUtil --hash mynewpassword</code>
 * </blockquote>
 * 
 * @param args
 *            arguments for this method as described above
 * @throws Exception
 *             Catches nothing; throws everything up.
 */
public static void main(final String[] args) throws Exception {
    // Print help if the user requested it, or if no arguments
    if (args.length == 0 || (args.length == 1 && HELP.equals(args[0]))) {
        System.out.println("Usage: CryptUtil [options] ");
        System.out.println("   --hash   password             create hash for password");
        System.out.println("   --verify password digest      verify password for digest");
        System.exit(0);
    }

    // User wants to hash the password
    if (HASH.equals(args[0])) {
        if (args.length < 2) {
            throw new IllegalArgumentException("Error: --hash requires a 'password' argument.");
        }
        final String password = args[1].trim();
        System.out.println(CryptoUtils.getSaltedPassword(password.getBytes("UTF-8")));
    }

    // User wants to verify an existing password
    else if (VERIFY.equals(args[0])) {
        if (args.length < 3) {
            throw new IllegalArgumentException("Error: --hash requires 'password' and 'digest' arguments.");
        }
        final String password = args[1].trim();
        final String digest = args[2].trim();
        System.out.println(CryptoUtils.verifySaltedPassword(password.getBytes("UTF-8"), digest));
    }

    else {
        System.out.println("Wrong usage. Try --help.");
    }
}

From source file:com.versul.main.MainClass.java

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

    if (args == null || args.length != 1) {
        throw new IllegalArgumentException(
                "Nmero de parmetros invlido ou parmetros no foram recebidos.");
    }/* ww w. j a v  a 2  s.  c o  m*/

    BasicConfigurator.configure();

    try {
        MainClass main = new MainClass();
        main.extractAndValidateParams(args[0]);
        main.createReport();
    } catch (Exception e) {
        log(e);
    }
}

From source file:net.anthonypoon.ngram.correlation.Main.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("a", "action", true, "Action");
    options.addOption("i", "input", true, "input");
    options.addOption("o", "output", true, "output");
    //options.addOption("f", "format", true, "Format");
    options.addOption("u", "upbound", true, "Year up bound");
    options.addOption("l", "lowbound", true, "Year low bound");
    options.addOption("t", "target", true, "Correlation Target URI"); // Can only take file from S# or HDFS
    options.addOption("L", "lag", true, "Lag factor");
    options.addOption("T", "threshold", true, "Correlation threshold");
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    Configuration conf = new Configuration();
    if (cmd.hasOption("lag")) {
        conf.set("lag", cmd.getOptionValue("lag"));
    }//from w  w w . j  a v a 2 s.c o  m
    if (cmd.hasOption("threshold")) {
        conf.set("threshold", cmd.getOptionValue("threshold"));
    }
    if (cmd.hasOption("upbound")) {
        conf.set("upbound", cmd.getOptionValue("upbound"));
    } else {
        conf.set("upbound", "9999");
    }
    if (cmd.hasOption("lowbound")) {
        conf.set("lowbound", cmd.getOptionValue("lowbound"));
    } else {
        conf.set("lowbound", "0");
    }
    if (cmd.hasOption("target")) {
        conf.set("target", cmd.getOptionValue("target"));
    } else {
        throw new Exception("Missing correlation target file uri");
    }
    Job job = Job.getInstance(conf);
    /**
    if (cmd.hasOption("format")) {
    switch (cmd.getOptionValue("format")) {
        case "compressed":
            job.setInputFormatClass(SequenceFileAsTextInputFormat.class);
            break;
        case "text":
            job.setInputFormatClass(KeyValueTextInputFormat.class);
            break;
    }
            
    }**/
    job.setJarByClass(Main.class);
    switch (cmd.getOptionValue("action")) {
    case "get-correlation":
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        for (String inputPath : cmd.getOptionValue("input").split(",")) {
            MultipleInputs.addInputPath(job, new Path(inputPath), KeyValueTextInputFormat.class,
                    CorrelationMapper.class);
        }
        job.setReducerClass(CorrelationReducer.class);
        break;
    default:
        throw new IllegalArgumentException("Missing action");
    }

    String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date());

    //FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input")));
    FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}

From source file:com.tamingtext.classifier.bayes.ClassifyDocument.java

public static void main(String[] args) {
    log.info("Command-line arguments: " + Arrays.toString(args));

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputOpt = obuilder.withLongName("input").withRequired(true)
            .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create())
            .withDescription("Input file").withShortName("i").create();

    Option modelOpt = obuilder.withLongName("model").withRequired(true)
            .withArgument(abuilder.withName("model").withMinimum(1).withMaximum(1).create())
            .withDescription("Model to use when classifying data").withShortName("m").create();

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();/*from   www  . j a v  a 2 s.  c o m*/

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(modelOpt).withOption(helpOpt)
            .create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        File inputFile = new File(cmdLine.getValue(inputOpt).toString());

        if (!inputFile.isFile()) {
            throw new IllegalArgumentException(inputFile + " does not exist or is not a file");
        }

        File modelDir = new File(cmdLine.getValue(modelOpt).toString());

        if (!modelDir.isDirectory()) {
            throw new IllegalArgumentException(modelDir + " does not exist or is not a directory");
        }

        BayesParameters p = new BayesParameters();
        p.set("basePath", modelDir.getCanonicalPath());
        Datastore ds = new InMemoryBayesDatastore(p);
        Algorithm a = new BayesAlgorithm();
        ClassifierContext ctx = new ClassifierContext(a, ds);
        ctx.initialize();

        //TODO: make the analyzer configurable
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
        TokenStream ts = analyzer.tokenStream(null,
                new InputStreamReader(new FileInputStream(inputFile), "UTF-8"));

        ArrayList<String> tokens = new ArrayList<String>(1000);
        while (ts.incrementToken()) {
            tokens.add(ts.getAttribute(CharTermAttribute.class).toString());
        }
        String[] document = tokens.toArray(new String[tokens.size()]);

        ClassifierResult[] cr = ctx.classifyDocument(document, "unknown", 5);

        for (ClassifierResult r : cr) {
            System.err.println(r.getLabel() + "\t" + r.getScore());
        }
    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
    } catch (IOException e) {
        log.error("IOException", e);
    } catch (InvalidDatastoreException e) {
        log.error("InvalidDataStoreException", e);
    } finally {

    }
}

From source file:com.mapr.synth.Synth.java

public static void main(String[] args)
        throws IOException, CmdLineException, InterruptedException, ExecutionException {
    final Options opts = new Options();
    CmdLineParser parser = new CmdLineParser(opts);
    try {// w  ww  .ja  va  2s  .  c  o  m
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println("Usage: " + "[ -count <number>G|M|K ] " + "-schema schema-file "
                + "[-quote DOUBLE_QUOTE|BACK_SLASH|OPTIMISTIC] " + "[-format JSON|TSV|CSV|XML ] "
                + "[-threads n] " + "[-output output-directory-name] ");
        throw e;
    }
    Preconditions.checkArgument(opts.threads > 0 && opts.threads <= 2000,
            "Must have at least one thread and no more than 2000");

    if (opts.threads > 1) {
        Preconditions.checkArgument(!"-".equals(opts.output),
                "If more than on thread is used, you have to use -output to set the output directory");
    }

    File outputDir = new File(opts.output);
    if (!"-".equals(opts.output)) {
        if (!outputDir.exists()) {
            Preconditions.checkState(outputDir.mkdirs(),
                    String.format("Couldn't create output directory %s", opts.output));
        }
        Preconditions.checkArgument(outputDir.exists() && outputDir.isDirectory(),
                String.format("Couldn't create directory %s", opts.output));
    }

    if (opts.schema == null) {
        throw new IllegalArgumentException("Must specify schema file using [-schema filename] option");
    }
    final SchemaSampler sampler = new SchemaSampler(opts.schema);
    final AtomicLong rowCount = new AtomicLong();

    final List<ReportingWorker> tasks = Lists.newArrayList();
    int limit = (opts.count + opts.threads - 1) / opts.threads;
    int remaining = opts.count;
    for (int i = 0; i < opts.threads; i++) {

        final int count = Math.min(limit, remaining);
        remaining -= count;

        tasks.add(new ReportingWorker(opts, sampler, rowCount, count, i));
    }

    final double t0 = System.nanoTime() * 1e-9;
    ExecutorService pool = Executors.newFixedThreadPool(opts.threads);
    ScheduledExecutorService blinker = Executors.newScheduledThreadPool(1);
    final AtomicBoolean finalRun = new AtomicBoolean(false);

    final PrintStream sideLog = new PrintStream(new FileOutputStream("side-log"));
    Runnable blink = new Runnable() {
        public double oldT;
        private long oldN;

        @Override
        public void run() {
            double t = System.nanoTime() * 1e-9;
            long n = rowCount.get();
            System.err.printf("%s\t%d\t%.1f\t%d\t%.1f\t%.3f\n", finalRun.get() ? "F" : "R", opts.threads,
                    t - t0, n, n / (t - t0), (n - oldN) / (t - oldT));
            for (ReportingWorker task : tasks) {
                ReportingWorker.ThreadReport r = task.report();
                sideLog.printf("\t%d\t%.2f\t%.2f\t%.2f\t%.1f\t%.1f\n", r.fileNumber, r.threadTime, r.userTime,
                        r.wallTime, r.rows / r.threadTime, r.rows / r.wallTime);
            }
            oldN = n;
            oldT = t;
        }
    };
    if (!"-".equals(opts.output)) {
        blinker.scheduleAtFixedRate(blink, 0, 10, TimeUnit.SECONDS);
    }
    List<Future<Integer>> results = pool.invokeAll(tasks);

    int total = 0;
    for (Future<Integer> result : results) {
        total += result.get();
    }
    Preconditions.checkState(total == opts.count, String
            .format("Expected to generate %d lines of output, but actually generated %d", opts.count, total));
    pool.shutdownNow();
    blinker.shutdownNow();
    finalRun.set(true);
    sideLog.close();
    blink.run();
}

From source file:edu.harvard.med.screensaver.io.libraries.LibraryContentsLoader.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    CommandLineApplication application = new CommandLineApplication(args);
    application.addCommandLineOption(/*from   w ww.jav a 2  s. c  o m*/
            OptionBuilder.hasArg().withArgName(LIBRARY_SHORT_NAME_OPTION[SHORT_OPTION_INDEX]).isRequired()
                    .withDescription(LIBRARY_SHORT_NAME_OPTION[DESCRIPTION_INDEX])
                    .withLongOpt(LIBRARY_SHORT_NAME_OPTION[LONG_OPTION_INDEX])
                    .create(LIBRARY_SHORT_NAME_OPTION[SHORT_OPTION_INDEX]));
    application.addCommandLineOption(OptionBuilder.hasArg().withArgName(INPUT_FILE_OPTION[SHORT_OPTION_INDEX])
            .isRequired().withDescription(INPUT_FILE_OPTION[DESCRIPTION_INDEX])
            .withLongOpt(INPUT_FILE_OPTION[LONG_OPTION_INDEX]).create(INPUT_FILE_OPTION[SHORT_OPTION_INDEX]));
    application.addCommandLineOption(
            OptionBuilder.isRequired(false).withDescription(RELEASE_IF_SUCCESS_OPTION[DESCRIPTION_INDEX])
                    .withLongOpt(RELEASE_IF_SUCCESS_OPTION[LONG_OPTION_INDEX])
                    .create(RELEASE_IF_SUCCESS_OPTION[SHORT_OPTION_INDEX]));

    application.processOptions(true, true);
    String libraryShortName = application
            .getCommandLineOptionValue(LIBRARY_SHORT_NAME_OPTION[SHORT_OPTION_INDEX]);
    File libraryContentsFile = application.getCommandLineOptionValue(INPUT_FILE_OPTION[SHORT_OPTION_INDEX],
            File.class);
    boolean releaseIfSuccess = application.isCommandLineFlagSet(RELEASE_IF_SUCCESS_OPTION[SHORT_OPTION_INDEX]);

    edu.harvard.med.screensaver.service.libraries.LibraryContentsLoader libraryContentsLoader = (edu.harvard.med.screensaver.service.libraries.LibraryContentsLoader) application
            .getSpringBean("libraryContentsLoader");
    edu.harvard.med.screensaver.service.libraries.LibraryContentsVersionManager libraryContentsVersionManager = (edu.harvard.med.screensaver.service.libraries.LibraryContentsVersionManager) application
            .getSpringBean("libraryContentsVersionManager");
    GenericEntityDAO dao = (GenericEntityDAO) application.getSpringBean("genericEntityDao");

    try {
        AdministratorUser admin = application.findAdministratorUser();
        Library library = dao.findEntityByProperty(Library.class, "shortName", libraryShortName);
        if (library == null) {
            throw new IllegalArgumentException("no library with short name: " + libraryShortName);
        }
        LibraryContentsVersion lcv = libraryContentsLoader.loadLibraryContents(library, admin, null /*TODO*/,
                new FileInputStream(libraryContentsFile));
        if (releaseIfSuccess) {
            log.info("releasing...");
            libraryContentsVersionManager.releaseLibraryContentsVersion(lcv, admin);
        }
    } catch (ParseErrorsException e) {
        for (ParseError error : e.getErrors()) {
            log.error(error.toString(), e);
        }
        System.exit(1);
    } catch (Exception e) {
        log.error("application exception", e);
        System.exit(1);
    }
}

From source file:com.tamingtext.tagging.LuceneTagExtractor.java

public static void main(String[] args) throws IOException {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputOpt = obuilder.withLongName("dir").withRequired(true)
            .withArgument(abuilder.withName("dir").withMinimum(1).withMaximum(1).create())
            .withDescription("The Lucene directory").withShortName("d").create();

    Option outputOpt = obuilder.withLongName("output").withRequired(false)
            .withArgument(abuilder.withName("output").withMinimum(1).withMaximum(1).create())
            .withDescription("The output directory").withShortName("o").create();

    Option maxOpt = obuilder.withLongName("max").withRequired(false)
            .withArgument(abuilder.withName("max").withMinimum(1).withMaximum(1).create())
            .withDescription(//from w  w  w  . ja va2  s  .  c o m
                    "The maximum number of vectors to output.  If not specified, then it will loop over all docs")
            .withShortName("m").create();

    Option fieldOpt = obuilder.withLongName("field").withRequired(true)
            .withArgument(abuilder.withName("field").withMinimum(1).withMaximum(1).create())
            .withDescription("The field in the index").withShortName("f").create();

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(maxOpt)
            .withOption(fieldOpt).create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        File file = new File(cmdLine.getValue(inputOpt).toString());

        if (!file.isDirectory()) {
            throw new IllegalArgumentException(file + " does not exist or is not a directory");
        }

        long maxDocs = Long.MAX_VALUE;
        if (cmdLine.hasOption(maxOpt)) {
            maxDocs = Long.parseLong(cmdLine.getValue(maxOpt).toString());
        }

        if (maxDocs < 0) {
            throw new IllegalArgumentException("maxDocs must be >= 0");
        }

        String field = cmdLine.getValue(fieldOpt).toString();

        PrintWriter out = null;
        if (cmdLine.hasOption(outputOpt)) {
            out = new PrintWriter(new FileWriter(cmdLine.getValue(outputOpt).toString()));
        } else {
            out = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"));
        }

        File output = new File("/home/drew/taming-text/delicious/training");
        output.mkdirs();

        emitTextForTags(file, output);

        IOUtils.close(Collections.singleton(out));
    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
    }

}