Example usage for org.apache.commons.cli CommandLine hasOption

List of usage examples for org.apache.commons.cli CommandLine hasOption

Introduction

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

Prototype

public boolean hasOption(char opt) 

Source Link

Document

Query to see if an option has been set.

Usage

From source file:edu.umass.cs.gnsclient.client.testing.BatchCreateTest.java

/**
 * The main routine run from the command line.
 *
 * @param args/*from w  w w  .j  av a  2  s  .c o m*/
 * @throws Exception
 */
public static void main(String args[]) throws Exception {
    CommandLine parser = initializeOptions(args);
    if (parser.hasOption("help")) {
        printUsage();
        System.exit(1);
    }
    String alias = parser.getOptionValue("alias");
    int guidCnt = Integer.parseInt(parser.getOptionValue("guidCnt", "10000"));
    int writeTo = Integer.parseInt(parser.getOptionValue("writeTo", "0"));
    new BatchCreateTest(alias != null ? alias : DEFAULT_ACCOUNT_ALIAS, guidCnt, writeTo);
    System.exit(0);
}

From source file:com.aerospike.examples.Main.java

/**
 * Main entry point.//from w ww. j a  v  a2s  .c  o m
 */
public static void main(String[] args) {

    try {
        Options options = new Options();
        options.addOption("h", "host", true, "Server hostname (default: localhost)");
        options.addOption("p", "port", true, "Server port (default: 3000)");
        options.addOption("U", "user", true, "User name");
        options.addOption("P", "password", true, "Password");
        options.addOption("n", "namespace", true, "Namespace (default: test)");
        options.addOption("s", "set", true, "Set name. Use 'empty' for empty set (default: demoset)");
        options.addOption("g", "gui", false, "Invoke GUI to selectively run tests.");
        options.addOption("d", "debug", false, "Run in debug mode.");
        options.addOption("u", "usage", false, "Print usage.");

        CommandLineParser parser = new PosixParser();
        CommandLine cl = parser.parse(options, args, false);

        if (args.length == 0 || cl.hasOption("u")) {
            logUsage(options);
            return;
        }
        Parameters params = parseParameters(cl);
        String[] exampleNames = cl.getArgs();

        if ((exampleNames.length == 0) && (!cl.hasOption("g"))) {
            logUsage(options);
            return;
        }

        // Check for all.
        for (String exampleName : exampleNames) {
            if (exampleName.equalsIgnoreCase("all")) {
                exampleNames = ExampleNames;
                break;
            }
        }

        if (cl.hasOption("d")) {
            Log.setLevel(Level.DEBUG);
        }

        if (cl.hasOption("g")) {
            GuiDisplay.startGui(params);
        } else {
            Console console = new Console();
            runExamples(console, params, exampleNames);
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:eu.scape_project.pc.hadoop.TikaIdentifyHadoopJob.java

/**
 * The main entry point.//from www . ja  va2  s.c o  m
 */
public static void main(String[] args) throws ParseException {
    Configuration conf = new Configuration();
    GenericOptionsParser gop = new GenericOptionsParser(conf, args);
    HadoopJobCliConfig pc = new HadoopJobCliConfig();
    CommandLineParser cmdParser = new PosixParser();
    CommandLine cmd = cmdParser.parse(HadoopJobOptions.OPTIONS, gop.getRemainingArgs());
    if ((args.length == 0) || (cmd.hasOption(HadoopJobOptions.HELP_OPT))) {
        HadoopJobOptions.exit("Usage", 0);
    } else {
        HadoopJobOptions.initOptions(cmd, pc);
    }
    String dir = pc.getDirStr();

    String name = pc.getHadoopJobName();
    if (name == null || name.equals("")) {
        name = "tika_identification";
    }

    try {
        Job job = new Job(conf, name);

        // local debugging
        //            job.getConfiguration().set("mapred.job.tracker", "local");
        //            job.getConfiguration().set("fs.default.name", "file:///");

        job.setJarByClass(TikaIdentifyHadoopJob.class);

        job.setMapperClass(TikaIdentifyMapper.class);
        //job.setCombinerClass(TikaIdentifyReducer.class);
        job.setReducerClass(TikaIdentifyReducer.class);

        job.setInputFormatClass(TextInputFormat.class);

        job.setOutputFormatClass(TextOutputFormat.class);
        //SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.NONE);

        //conf.setMapOutputKeyClass(Text.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        SequenceFileInputFormat.addInputPath(job, new Path(dir));
        String outpath = "output/" + System.currentTimeMillis() + "tid";
        FileOutputFormat.setOutputPath(job, new Path(outpath));
        job.waitForCompletion(true);
        System.out.print(outpath);
        System.exit(0);
    } catch (Exception e) {
        logger.error("I/O error", e);
    }
}

From source file:gobblin.test.TestWorker.java

@SuppressWarnings("all")
public static void main(String[] args) throws Exception {
    // Build command-line options
    Option configOption = OptionBuilder.withArgName("framework config file")
            .withDescription("Configuration properties file for the framework").hasArgs().withLongOpt("config")
            .create('c');
    Option jobConfigsOption = OptionBuilder.withArgName("job config files")
            .withDescription("Comma-separated list of job configuration files").hasArgs()
            .withLongOpt("jobconfigs").create('j');
    Option modeOption = OptionBuilder.withArgName("run mode")
            .withDescription("Test mode (schedule|run); 'schedule' means scheduling the jobs, "
                    + "whereas 'run' means running the jobs immediately")
            .hasArg().withLongOpt("mode").create('m');
    Option helpOption = OptionBuilder.withArgName("help").withDescription("Display usage information")
            .withLongOpt("help").create('h');

    Options options = new Options();
    options.addOption(configOption);/*from   w  w w  .j av  a  2 s  .  c om*/
    options.addOption(jobConfigsOption);
    options.addOption(modeOption);
    options.addOption(helpOption);

    // Parse command-line options
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption('h')) {
        printUsage(options);
        System.exit(0);
    }

    // Start the test worker with the given configuration properties
    Configuration config = new PropertiesConfiguration(cmd.getOptionValue('c'));
    Properties properties = ConfigurationConverter.getProperties(config);
    TestWorker testWorker = new TestWorker(properties);
    testWorker.start();

    // Job running mode
    Mode mode = Mode.valueOf(cmd.getOptionValue('m').toUpperCase());

    // Get the list of job configuration files
    List<String> jobConfigFiles = Lists
            .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(cmd.getOptionValue('j')));

    CountDownLatch latch = new CountDownLatch(jobConfigFiles.size());
    for (String jobConfigFile : jobConfigFiles) {
        // For each job, load the job configuration, then run or schedule the job.
        Properties jobProps = new Properties();
        jobProps.load(new FileReader(jobConfigFile));
        jobProps.putAll(properties);
        testWorker.runJob(jobProps, mode, new TestJobListener(latch));
    }
    // Wait for all jobs to finish
    latch.await();

    testWorker.stop();
}

From source file:eu.scape_project.tika_identify.TikaIdentification.java

public static void main(String[] args)
        throws ParseException, IOException, InterruptedException, ClassNotFoundException {
    CommandLineParser cmdParser = new PosixParser();

    TikaCliOptions tikaCliOpts = new TikaCliOptions();
    appConfig = new TikaCliConfig();

    CommandLine cmd = cmdParser.parse(tikaCliOpts.options, args);
    if ((args.length == 0) || (cmd.hasOption(tikaCliOpts.HELP_OPT))) {
        tikaCliOpts.exit("Help", 0);
    } else {/*from   ww w  . j  a v a  2 s  . c  o m*/
        tikaCliOpts.initOptions(cmd, appConfig);
        TikaIdentification tc = new TikaIdentification();
        if (appConfig.isLocal()) {
            tc.startApplication();
        } else {
            tc.startHadoopJob();
        }
    }
}

From source file:com.adavr.player.Launcher.java

public static void main(String[] args) {
    CommandLine cl;
    try {//from   w w  w  .ja  v  a 2s.  c  o m
        cl = new BasicParser().parse(OPTIONS, args);
    } catch (ParseException ex) {
        showUsage();
        return;
    }

    if (cl.hasOption("help")) {
        showUsage();
        return;
    }

    ApplicationContext appCtx = (ApplicationContext) loadClass(cl.getOptionValue("context"));
    if (appCtx == null) {
        System.out.println("Failed to load App Context");
        appCtx = new VLCApplication();
    }
    if (cl.hasOption("source")) {
        String src = cl.getOptionValue("source");
        appCtx.getMediaContext().setMedia(src);
    }

    Application application = new Application(appCtx);
    application.setVSync(cl.hasOption("vsync"));
    if (cl.hasOption("factory")) {
        String className = cl.getOptionValue("factory");
        HMDRenderContextFactory factory = (HMDRenderContextFactory) loadClass(className);
        if (factory != null) {
            application.setHMDRenderContextFactory(factory);
        }
    }

    application.run();
}

From source file:eu.fbk.utils.twm.FormPageSearcher.java

public static void main(final String args[]) throws Exception {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "configuration/log-config.txt";
    }//from   www. j  a va 2  s  .  c o  m

    PropertyConfigurator.configure(logConfig);
    final Options options = new Options();
    try {
        OptionBuilder.withArgName("index");
        OptionBuilder.hasArg();
        OptionBuilder.withDescription("open an index with the specified name");
        OptionBuilder.isRequired();
        OptionBuilder.withLongOpt("index");
        final Option indexNameOpt = OptionBuilder.create("i");
        OptionBuilder.withArgName("interactive-mode");
        OptionBuilder.withDescription("enter in the interactive mode");
        OptionBuilder.withLongOpt("interactive-mode");
        final Option interactiveModeOpt = OptionBuilder.create("t");
        OptionBuilder.withArgName("search");
        OptionBuilder.hasArg();
        OptionBuilder.withDescription("search for the specified key");
        OptionBuilder.withLongOpt("search");
        final Option searchOpt = OptionBuilder.create("s");
        OptionBuilder.withArgName("key-freq");
        OptionBuilder.hasArg();
        OptionBuilder.withDescription("read the keys' frequencies from the specified file");
        OptionBuilder.withLongOpt("key-freq");
        final Option freqFileOpt = OptionBuilder.create("f");
        OptionBuilder.withArgName("minimum-freq");
        // Option keyFieldNameOpt =
        // OptionBuilder.withArgName("key-field-name").hasArg().withDescription("use the specified name for the field key").withLongOpt("key-field-name").create("k");
        // Option valueFieldNameOpt =
        // OptionBuilder.withArgName("value-field-name").hasArg().withDescription("use the specified name for the field value").withLongOpt("value-field-name").create("v");
        final Option minimumKeyFreqOpt = OptionBuilder.hasArg()
                .withDescription("minimum key frequency of cached values (default is " + DEFAULT_MIN_FREQ + ")")
                .withLongOpt("minimum-freq").create("m");
        OptionBuilder.withArgName("int");
        final Option notificationPointOpt = OptionBuilder.hasArg()
                .withDescription(
                        "receive notification every n pages (default is " + DEFAULT_NOTIFICATION_POINT + ")")
                .withLongOpt("notification-point").create("b");
        options.addOption("h", "help", false, "print this message");
        options.addOption("v", "version", false, "output version information and exit");

        options.addOption(indexNameOpt);
        options.addOption(interactiveModeOpt);
        options.addOption(searchOpt);
        options.addOption(freqFileOpt);
        // options.addOption(keyFieldNameOpt);
        // options.addOption(valueFieldNameOpt);
        options.addOption(minimumKeyFreqOpt);
        options.addOption(notificationPointOpt);

        final CommandLineParser parser = new PosixParser();
        final CommandLine line = parser.parse(options, args);

        if (line.hasOption("help") || line.hasOption("version")) {
            throw new ParseException("");
        }

        int minFreq = DEFAULT_MIN_FREQ;
        if (line.hasOption("minimum-freq")) {
            minFreq = Integer.parseInt(line.getOptionValue("minimum-freq"));
        }

        int notificationPoint = DEFAULT_NOTIFICATION_POINT;
        if (line.hasOption("notification-point")) {
            notificationPoint = Integer.parseInt(line.getOptionValue("notification-point"));
        }

        final FormPageSearcher pageFormSearcher = new FormPageSearcher(line.getOptionValue("index"));
        pageFormSearcher.setNotificationPoint(notificationPoint);
        /*
         * logger.debug(line.getOptionValue("key-field-name") + "\t" +
         * line.getOptionValue("value-field-name")); if (line.hasOption("key-field-name")) {
         * pageFormSearcher.setKeyFieldName(line.getOptionValue("key-field-name")); } if
         * (line.hasOption("value-field-name")) {
         * pageFormSearcher.setValueFieldName(line.getOptionValue("value-field-name")); }
         */
        if (line.hasOption("key-freq")) {
            pageFormSearcher.loadCache(line.getOptionValue("key-freq"), minFreq);
        }
        if (line.hasOption("search")) {
            logger.debug("searching " + line.getOptionValue("search") + "...");
            final FreqSetSearcher.Entry[] result = pageFormSearcher.search(line.getOptionValue("search"));
            logger.info(Arrays.toString(result));
        }
        if (line.hasOption("interactive-mode")) {
            pageFormSearcher.interactive();
        }
    } catch (final ParseException e) {
        // oops, something went wrong
        if (e.getMessage().length() > 0) {
            System.out.println("Parsing failed: " + e.getMessage() + "\n");
        }
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(400,
                "java -cp dist/thewikimachine.jar org.fbk.cit.hlt.thewikimachine.index.FormPageSearcher", "\n",
                options, "\n", true);
    }
}

From source file:eu.scape_project.arc2warc.Arc2WarcHadoopJob.java

/**
 * Main entry point./*from   w w w .j a v  a 2s  . com*/
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    // Command line interface
    config = new CliConfig();
    CommandLineParser cmdParser = new PosixParser();
    GenericOptionsParser gop = new GenericOptionsParser(conf, args);
    CommandLine cmd = cmdParser.parse(Options.OPTIONS, gop.getRemainingArgs());
    if ((args.length == 0) || (cmd.hasOption(Options.HELP_OPT))) {
        Options.exit("Usage", 0);
    } else {
        Options.initOptions(cmd, config);
    }

    startHadoopJob(conf);

}

From source file:eu.scape_project.pc.hadoop.DroidIdentifyHadoopJob.java

/**
 * The main entry point./* w  ww. j ava2s. c om*/
 */
public static void main(String[] args) throws ParseException {
    Configuration conf = new Configuration();
    GenericOptionsParser gop = new GenericOptionsParser(conf, args);
    HadoopJobCliConfig pc = new HadoopJobCliConfig();
    CommandLineParser cmdParser = new PosixParser();
    CommandLine cmd = cmdParser.parse(HadoopJobOptions.OPTIONS, gop.getRemainingArgs());
    if ((args.length == 0) || (cmd.hasOption(HadoopJobOptions.HELP_OPT))) {
        HadoopJobOptions.exit("Usage", 0);
    } else {
        HadoopJobOptions.initOptions(cmd, pc);
    }
    String dir = pc.getDirStr();

    String name = pc.getHadoopJobName();
    if (name == null || name.equals("")) {
        name = "droid_identification";
    }

    try {
        Job job = new Job(conf, name);

        // local debugging
        //            job.getConfiguration().set("mapred.job.tracker", "local");
        //            job.getConfiguration().set("fs.default.name", "file:///");

        job.setJarByClass(DroidIdentifyHadoopJob.class);

        job.setMapperClass(DroidIdentifyMapper.class);
        //job.setCombinerClass(DroidIdentifyReducer.class);
        job.setReducerClass(DroidIdentifyReducer.class);

        job.setInputFormatClass(TextInputFormat.class);

        job.setOutputFormatClass(TextOutputFormat.class);
        //SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.NONE);

        //conf.setMapOutputKeyClass(Text.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        SequenceFileInputFormat.addInputPath(job, new Path(dir));
        String outpath = "output/" + System.currentTimeMillis() + "dri";
        FileOutputFormat.setOutputPath(job, new Path(outpath));
        job.waitForCompletion(true);
        System.out.print(outpath);
        System.exit(0);
    } catch (Exception e) {
        logger.error("I/O error", e);
    }
}

From source file:gobblin.yarn.GobblinApplicationMaster.java

public static void main(String[] args) throws Exception {
    Options options = buildOptions();//  w  w w.  j  a  v a  2  s  . c o m
    try {
        CommandLine cmd = new DefaultParser().parse(options, args);
        if (!cmd.hasOption(GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME)) {
            printUsage(options);
            System.exit(1);
        }

        Log4jConfigurationHelper.updateLog4jConfiguration(GobblinApplicationMaster.class,
                GobblinYarnConfigurationKeys.GOBBLIN_YARN_LOG4J_CONFIGURATION_FILE,
                GobblinYarnConfigurationKeys.GOBBLIN_YARN_LOG4J_CONFIGURATION_FILE);

        LOGGER.info(JvmUtils.getJvmInputArguments());

        ContainerId containerId = ConverterUtils
                .toContainerId(System.getenv().get(ApplicationConstants.Environment.CONTAINER_ID.key()));

        try (GobblinApplicationMaster applicationMaster = new GobblinApplicationMaster(
                cmd.getOptionValue(GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME), containerId,
                ConfigFactory.load(), new YarnConfiguration())) {

            applicationMaster.start();
        }
    } catch (ParseException pe) {
        printUsage(options);
        System.exit(1);
    }
}