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:de.tudarmstadt.ukp.similarity.experiments.coling2012.Pipeline.java

public static void main(String[] args) throws Exception {
    DATASET_DIR = DKProContext.getContext().getWorkspace().getAbsolutePath() + "/Datasets/###/ds";
    GOLDSTANDARD_DIR = DKProContext.getContext().getWorkspace().getAbsolutePath() + "/Datasets/###/gs";

    Options options = new Options();
    options.addOption("d", "dataset", true, "dataset to evaluate: " + StringUtils.join(Dataset.values(), ", "));
    options.addOption("c", "classifier", true,
            "classifier to use: " + StringUtils.join(WekaClassifier.values(), ", "));

    CommandLineParser parser = new PosixParser();
    try {/*from  w w  w  .j a  va2 s .  c  om*/
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("d") && cmd.hasOption("c")) {
            Dataset dataset = Dataset.valueOf(cmd.getOptionValue("d"));
            WekaClassifier wekaClassifier = WekaClassifier.valueOf(cmd.getOptionValue("c"));

            runCV(dataset, wekaClassifier);
        } else {
            new HelpFormatter().printHelp(Pipeline.class.getSimpleName(), options, true);
        }
    } catch (ParseException e) {
        new HelpFormatter().printHelp(Pipeline.class.getSimpleName(), options);
    }
}

From source file:com.basingwerk.utilisation.Utilisation.java

public static void main(final String[] args) {
    String dataFile = null;/*w  w w  .  j av  a 2s. c  o  m*/

    Options options = new Options();

    Option helpOption = new Option("h", "help", false, "print this help");
    Option serverURLOption = new Option("l", "logfile", true, "log file");

    options.addOption(helpOption);
    options.addOption(serverURLOption);

    CommandLineParser argsParser = new PosixParser();

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

        if (commandLine.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

        dataFile = commandLine.getOptionValue(serverURLOption.getOpt());
        String[] otherArgs = commandLine.getArgs();

        if (dataFile == null || otherArgs.length > 1) {
            System.out.println("Please specify a logfile");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
    }

    final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile));
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}

From source file:ezbake.thrift.VisibilityBase64Converter.java

public static void main(String[] args) {
    try {/*  w  w w. j  a  v  a  2  s .c  om*/
        Options options = new Options();
        options.addOption("d", "deserialize", false,
                "deserialize base64 visibility, if not present tool will serialize");
        options.addOption("v", "visibility", true,
                "formalVisibility to serialize, or base64 encoded string to deserialize");
        options.addOption("h", "help", false, "display usage info");

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

        if (cmd.hasOption("h")) {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("thrift-visibility-converter", options);
            return;
        }

        String input = cmd.getOptionValue("v");
        boolean deserialize = cmd.hasOption("d");

        String output;
        if (deserialize) {
            if (input == null) {
                System.err.println("Cannot deserialize empty string");
                System.exit(1);
            }
            output = ThriftUtils.deserializeFromBase64(Visibility.class, input).toString();
        } else {
            Visibility visibility = new Visibility();
            if (input == null) {
                input = "(empty visibility)";
            } else {
                visibility.setFormalVisibility(input);
            }
            output = ThriftUtils.serializeToBase64(visibility);
        }
        String operation = deserialize ? "deserialize" : "serialize";
        System.out.println("operation: " + operation);
        System.out.println("input: " + input);
        System.out.println("output: " + output);
    } catch (TException | ParseException e) {
        System.out.println("An error occurred: " + e.getMessage());
        System.exit(1);
    }
}

From source file:fr.tpt.atlanalyser.tests.TestOldAGTExpPost2Pre.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {

    // URL resource = Thread.currentThread().getContextClassLoader()
    // .getResource("OldAGTExp");
    // System.out.println(resource.toString());
    // File f = new File(resource.getPath());
    // System.out.println(f.toString());
    // System.out.println(f.isDirectory());
    // System.exit(0);

    Options options = new Options();
    options.addOption(/*from   w ww.  j a v  a 2s  .  co  m*/
            OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j"));
    options.addOption(OptionBuilder.withDescription("Display help").create("h"));

    CommandLineParser parser = new BasicParser();
    int jobs = 1;
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            new HelpFormatter().printHelp(TestOldAGTExpPost2Pre.class.getSimpleName(), options);
            System.exit(0);
        }

        if (cmd.hasOption("j")) {
            jobs = Integer.parseInt(cmd.getOptionValue("j"));
        }
    } catch (Exception e) {
        System.out.println("Incorrect command line arguments");
        new HelpFormatter().printHelp(TestOldAGTExpPost2Pre.class.getSimpleName(), options);
        System.exit(1);
    }

    new TestOldAGTExpPost2Pre(models().iterator().next()[0], jobs).testPost2Pre();
}

From source file:ca.uqam.mglunit.Runner.java

public static void main(String[] args) throws Exception {
    Runner runner = new Runner();
    TestResultLogger logger = new TestResultLogger();
    logger.setOutputStream(System.out);

    try {//from w ww .  j  a  v a 2  s  .  c  o  m
        CommandLineParser parser = new GnuParser();
        CommandLine cli = parser.parse(cliOptions, args);
        if (cli.hasOption("help") || cli.getArgs().length == 0)
            printHelp();
        else {
            configureLogger(logger, cli);
            runner.setTestResultLogger(logger);
            runner.setSpecificationClass(Class.forName(cli.getArgs()[0]));
            runner.run();
        }
    } catch (ParseException ex) {
        printHelp();
    } finally {
        logger.print();
    }
}

From source file:com.linkedin.bowser.tool.REPLCommandLine.java

public static void main(String... args) throws Exception {
    Logger root = Logger.getRootLogger();

    Options options = new Options();
    options.addOption("v", "verbose", false, "verbose output");
    options.addOption("t", "threads", true, "parallel threads");
    CommandLineParser parser = new PosixParser();
    CommandLine cmdline = parser.parse(options, args);

    if (cmdline.hasOption("v"))
        root.setLevel(Level.DEBUG);
    else/*from   w  w w  . j  a v a2  s. c o m*/
        root.setLevel(Level.INFO);

    REPLCommandLine cmd = new REPLCommandLine(cmdline.hasOption("v"),
            cmdline.hasOption("t") ? Integer.parseInt(cmdline.getOptionValue("t")) : null);
    cmd.doRun();
}

From source file:com.palmercox.rustcryptotester.App.java

public static void main(String[] args) throws Exception {
    final CommandLineParser clp = new GnuParser();
    final CommandLine cl = clp.parse(getOptions(), args);

    if (cl.hasOption("help")) {
        help();/*from   ww  w .jav  a 2s .c om*/
        return;
    }

    final String rustExec;
    if (cl.hasOption("rustexec")) {
        rustExec = cl.getOptionValue("rustexec");
    } else {
        help();
        return;
    }

    System.out.println("Starting Rust Crypto Tests:");

    boolean ok = true;

    final RustCryptRunner runner = new RustCryptRunner(new File(rustExec));
    try {
        for (final Tester t : getTesters()) {
            final Random rand = new Random(0);
            final boolean result = t.test(runner, rand);
            System.out.println("Test passed: " + result);
            ok = ok && result;
        }
    } finally {
        runner.close();
    }

    System.out.println("Done");

    if (!ok) {
        System.exit(1);
    }
}

From source file:com.sourcethought.simpledaemon.EchoTask.java

public static void main(String[] args) throws Exception {
    // setup command line options
    Options options = new Options();
    options.addOption("h", "help", false, "print this help screen");

    // read command line options
    CommandLineParser parser = new PosixParser();
    try {//from   w  w  w.  j a  v a  2 s  .  com
        CommandLine cmdline = parser.parse(options, args);

        if (cmdline.hasOption("help") || cmdline.hasOption("h")) {
            System.out.println("SimpleDaemon Version " + Main.version);

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(
                    "java -cp lib/*:target/SimpleDaemon-1.0-SNAPSHOT.jar com.sourcethought.simpledaemon.Main",
                    options);
            return;
        }

        final SimpleDaemon daemon = new SimpleDaemon();
        daemon.start();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                if (daemon.isRunning()) {
                    try {
                        System.out.println("Shutting down daemon...");
                        daemon.stop();
                    } catch (Exception ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }));

    } catch (ParseException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.google.api.codegen.CodeGeneratorTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(Option.builder().longOpt("descriptor_set")
            .desc("The descriptor set representing the compiled input protos.").hasArg()
            .argName("DESCRIPTOR-SET").required(true).build());
    options.addOption(/*from  w  ww . jav a 2 s . c  om*/
            Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.")
                    .hasArg().argName("SERVICE-YAML").required(true).build());
    options.addOption(Option.builder().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.")
            .hasArg().argName("GAPIC-YAML").required(true).build());
    options.addOption(Option.builder().longOpt("package_yaml")
            .desc("The package metadata YAML configuration file.").hasArg().argName("PACKAGE-YAML").build());
    options.addOption(Option.builder("o").longOpt("output")
            .desc("The directory in which to output the generated client library.").hasArg()
            .argName("OUTPUT-DIRECTORY").build());
    options.addOption(Option.builder().longOpt("enabled_artifacts")
            .desc("Optional. Artifacts enabled for the generator. "
                    + "Currently supports 'surface' and 'test'.")
            .hasArg().argName("ENABLED_ARTIFACTS").required(false).build());

    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formater = new HelpFormatter();
        formater.printHelp("CodeGeneratorTool", options);
    }

    int exitCode = generate(cl.getOptionValue("descriptor_set"), cl.getOptionValues("service_yaml"),
            cl.getOptionValues("gapic_yaml"), cl.getOptionValue("package_yaml"),
            cl.getOptionValue("output", ""), cl.getOptionValues("enabled_artifacts"));
    System.exit(exitCode);
}

From source file:com.linkedin.python.importer.ImporterCLI.java

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

    Options options = createOptions();/*from   w  w w . jav a 2s .  c o  m*/

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

    if (line.hasOption("quite")) {
        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.WARN);
    }

    final File repoPath = new File(line.getOptionValue("repo"));
    final DependencySubstitution replacements = new DependencySubstitution(buildSubstitutionMap(line));

    repoPath.mkdirs();

    if (!repoPath.exists() || !repoPath.isDirectory()) {
        throw new RuntimeException(
                "Unable to continue, " + repoPath.getAbsolutePath() + " does not exist, or is not a directory");
    }

    for (String dependency : line.getArgList()) {
        new DependencyDownloader(dependency, repoPath, replacements).download();
    }

    logger.info("Execution Finished!");
}