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

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

Introduction

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

Prototype

public String[] getArgs() 

Source Link

Document

Retrieve any left-over non-recognized options and arguments

Usage

From source file:com.slothpetrochemical.bridgeprob.BridgeProblemApp.java

public static void main(final String[] args) throws ParseException {
    Options commandLineOptions = createOptions();
    PosixParser clParser = new PosixParser();
    CommandLine cl = clParser.parse(commandLineOptions, args);

    if (cl.getArgs().length == 0 || cl.hasOption("h")) {
        new HelpFormatter().printHelp("crossing_times...", commandLineOptions);
    } else {/*from www .  j a va  2 s  .  co  m*/
        String[] clArgs = cl.getArgs();
        Integer[] times = new Integer[clArgs.length];
        for (int i = 0; i < clArgs.length; ++i) {
            Integer intTime = Integer.parseInt(clArgs[i]);
            times[i] = intTime;
        }
        Arrays.sort(times);
        BridgeProblemApp app = new BridgeProblemApp(Arrays.asList(times));
        app.run();
    }
}

From source file:com.sr.eb.compiler.Main.java

public static void main(String[] args) throws Throwable {
    try {//from w ww .j  a  v  a  2 s .com
        Options options = new Options();

        options.addOption("v", "verbose", false, "Enables verbose compiler output.");
        options.addOption("ee", "easterEgg", false, "Enables compiler easter eggs, DO NOT USE!");

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

        if (cmd.getArgs().length > 0) {
            int start = -1;
            while (true) {
                start++;
                if (options.getOption(cmd.getArgs()[start]) == null)
                    break;
            }

            String[] sourceFiles = Arrays.copyOfRange(cmd.getArgs(), start, cmd.getArgs().length);

            // TODO
        } else {
            System.out.println("Expected source files, got none!");
            System.out.println("Usage: ebc [options] <source files>");
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    /* ----- Testing ----- */
    Lexer lexer = Lexer.newInstance();
    Parser parser = Parser.newInstance();

    try (InputStream in = new FileInputStream("test.eb")) {
        lexer.reset(Utils.readAll(in));
    }

    List<Token> tokens = lexer.tokenize();
    parser.reset(tokens);
    SyntaxTree t = parser.parse();

    ASTPrettyPrinter.print(t);
}

From source file:dk.statsbiblioteket.jpar2.filecompare.FileCompare.java

/**
 * Main method. //www .  j av  a2s  .  co m
 * @param args
 */
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("s", "slices", true, "The number of slices to use in the comparison");

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        args = cmd.getArgs();
        if (!cmd.hasOption("s") || args.length != 2) {
            System.exit(2);
        }
        int slices = Integer.parseInt(cmd.getOptionValue("s").trim());

        File f1 = new File(args[0]);
        File f2 = new File(args[1]);
        if (f1.length() == f2.length()) {
            int sliceSize = (int) (f1.length() / slices);//rounding here...

            DataFile df1 = new DataFile(f1, sliceSize);
            DataFile df2 = new DataFile(f2, sliceSize);

            List<Integer> defectIndexes = df1.compareWithIndex(df2);

            for (int index : defectIndexes) {
                System.out.println("index " + index + ", from " + index * sliceSize + " to "
                        + (index + 1) * sliceSize + " is defect");
            }
            if (defectIndexes.size() == 0) {
                System.out.println("Files are identical");
            }

        } else {
            System.out.println("Files differ in length, cannot help you");
        }
    } catch (ParseException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

}

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 {//  w w w. ja va2  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.googlecode.hiberpcml.generator.Tool.java

public static void main(String arg[]) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();

    Option destinyOpt = new Option("t", "target", true, "target of the generated classes");
    destinyOpt.setArgName("target");
    options.addOption(destinyOpt);//from w ww.  java  2 s.  com

    Option packageOpt = new Option("p", "package", true, "Java Package of the generated classes");
    packageOpt.setArgName("package");
    options.addOption(packageOpt);

    Option webServiceOpt = new Option("w", "webservice", true, "build webservice classes");
    webServiceOpt.setArgs(2);
    webServiceOpt.setArgName("serviceName service");
    options.addOption(webServiceOpt);

    options.addOption(webServiceOpt);

    CommandLine cmd = parser.parse(options, arg);
    if (cmd.getArgs().length == 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("generator [options] FILE|DIRECTORY.", options);
        System.exit(1);
    }

    Pcml pcml;
    ArrayList<File> filesToParse = getFilesToParse(cmd.getArgs()[0]);
    JCodeModel cm = new JCodeModel();
    JPackage _package = cm._package(cmd.getOptionValue("p", ""));
    Generator generator;
    WSGenerator wsGenerator = null;
    File targetFile = new File(cmd.getOptionValue("t", "./target"));

    targetFile.mkdirs();
    if (cmd.hasOption("w")) {
        wsGenerator = new WSGenerator(_package, cmd.getOptionValues("w")[0], cmd.getOptionValues("w")[1]);
    }

    for (File file : filesToParse) {
        pcml = Util.load(file);
        if (cmd.hasOption("w")) {
            wsGenerator.addMethod(pcml);
        } else {
            generator = new Generator();
            generator.generate(_package, pcml);
        }
    }
    cm.build(targetFile);
}

From source file:com.knewton.mapreduce.example.SSTableMRExample.java

public static void main(String[] args)
        throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException, ParseException {

    long startTime = System.currentTimeMillis();
    Options options = buildOptions();/*from   w w w.j av  a  2 s  .  c om*/

    CommandLineParser cliParser = new BasicParser();
    CommandLine cli = cliParser.parse(options, args);
    if (cli.getArgs().length < 2 || cli.hasOption('h')) {
        printUsage(options);
    }
    Job job = getJobConf(cli);

    job.setJarByClass(SSTableMRExample.class);
    job.setOutputKeyClass(LongWritable.class);
    job.setOutputValueClass(StudentEventWritable.class);

    job.setMapperClass(StudentEventMapper.class);
    job.setReducerClass(StudentEventReducer.class);

    job.setInputFormatClass(SSTableColumnInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);
    // input arg
    String inputPaths = cli.getArgs()[0];
    LOG.info("Setting initial input paths to {}", inputPaths);
    SSTableInputFormat.addInputPaths(job, inputPaths);
    // output arg
    FileOutputFormat.setOutputPath(job, new Path(cli.getArgs()[1]));
    if (cli.hasOption('c')) {
        LOG.info("Using compression for output.");
        FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
        FileOutputFormat.setCompressOutput(job, true);
    }
    job.waitForCompletion(true);
    LOG.info("Total runtime: {}s", (System.currentTimeMillis() - startTime) / 1000);
}

From source file:fr.liglab.consgap.Main.java

public static void main(String[] args) throws IOException {
    Options options = new Options();
    CommandLineParser parser = new PosixParser();

    options.addOption("s", false, "Sparse: use int lists instead of bitsets to represent positions");
    options.addOption("b", false, "Benchmark mode : sequences are not outputted at all");
    options.addOption("h", false, "Show help");
    options.addOption("w", false,
            "Use breadth first exploration instead of depth first. Usually less efficient.");
    options.addOption("t", true,
            "How many threads will be launched (defaults to your machine's processors count)");
    options.addOption("l", false, "Use lcm style, read dataset to generate candidates");
    options.addOption("f", true,
            "Sequences filtering frequency, expressed in number of outputs. Recommended value is 100, avoids some redundant explorations.");
    options.addOption("sep", true, "separator in the dataset files (defaults to tabulation)");
    try {//from  www.jav a2  s.co  m
        CommandLine cmd = parser.parse(options, args);

        if (cmd.getArgs().length != 5 || cmd.hasOption('h')) {
            printMan(options);
        } else {
            standalone(cmd);
        }
    } catch (ParseException e) {
        printMan(options);
    }
}

From source file:com.spotify.cassandra.opstools.CountTombstones.java

/**
 * Counts the number of tombstones, per row, in a given SSTable
 *
 * Assumes RandomPartitioner, standard columns and UTF8 encoded row keys
 *
 * Does not require a cassandra.yaml file or system tables.
 *
 * @param args command lines arguments//from w w w  . j a v  a 2s.com
 *
 * @throws java.io.IOException on failure to open/read/write files or output streams
 */
public static void main(String[] args) throws IOException, ParseException {
    String usage = String.format("Usage: %s [-l] <sstable> [<sstable> ...]%n", CountTombstones.class.getName());

    final Options options = new Options();
    options.addOption("l", "legend", false, "Include column name explanation");
    options.addOption("p", "partitioner", true, "The partitioner used by database");

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

    if (cmd.getArgs().length < 1) {
        System.err.println("You must supply at least one sstable");
        System.err.println(usage);
        System.exit(1);
    }

    // Fake DatabaseDescriptor settings so we don't have to load cassandra.yaml etc
    Config.setClientMode(true);
    String partitionerName = String.format("org.apache.cassandra.dht.%s",
            options.hasOption("p") ? options.getOption("p") : "RandomPartitioner");
    try {
        Class<?> clazz = Class.forName(partitionerName);
        IPartitioner partitioner = (IPartitioner) clazz.newInstance();
        DatabaseDescriptor.setPartitioner(partitioner);
    } catch (Exception e) {
        throw new RuntimeException("Can't instantiate partitioner " + partitionerName);
    }

    PrintStream out = System.out;

    for (String arg : cmd.getArgs()) {
        String ssTableFileName = new File(arg).getAbsolutePath();

        Descriptor descriptor = Descriptor.fromFilename(ssTableFileName);

        run(descriptor, cmd, out);
    }

    System.exit(0);
}

From source file:co.cask.cdap.data.tools.CoprocessorBuildTool.java

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

    Options options = new Options().addOption(new Option("h", "help", false, "Print this usage message."))
            .addOption(new Option("f", "force", false, "Overwrites any coprocessors that already exist."));

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);
    String[] commandArgs = commandLine.getArgs();

    // if help is an option, or if there isn't a single 'ensure' command, print usage and exit.
    if (commandLine.hasOption("h") || commandArgs.length != 1 || !"check".equalsIgnoreCase(commandArgs[0])) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(CoprocessorBuildTool.class.getName() + " check",
                "Checks that HBase coprocessors required by CDAP are loaded onto HDFS. "
                        + "If not, the coprocessors are built and placed on HDFS.",
                options, "");
        System.exit(0);/*w w  w  . j  a v  a 2 s. c  o  m*/
    }

    boolean overwrite = commandLine.hasOption("f");

    CConfiguration cConf = CConfiguration.create();
    Configuration hConf = HBaseConfiguration.create();

    Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf),
            // for LocationFactory
            new PrivateModule() {
                @Override
                protected void configure() {
                    bind(FileContext.class).toProvider(FileContextProvider.class).in(Scopes.SINGLETON);
                    expose(LocationFactory.class);
                }

                @Provides
                @Singleton
                private LocationFactory providesLocationFactory(Configuration hConf, CConfiguration cConf,
                        FileContext fc) {
                    final String namespace = cConf.get(Constants.CFG_HDFS_NAMESPACE);
                    return new FileContextLocationFactory(hConf, fc, namespace);
                }
            });

    try {
        SecurityUtil.loginForMasterService(cConf);
    } catch (Exception e) {
        LOG.error("Failed to login as CDAP user", e);
        System.exit(1);
    }

    LocationFactory locationFactory = injector.getInstance(LocationFactory.class);
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    CoprocessorManager coprocessorManager = new CoprocessorManager(cConf, locationFactory, tableUtil);

    try {
        Location location = coprocessorManager.ensureCoprocessorExists(overwrite);
        LOG.info("coprocessor exists at {}.", location);
    } catch (IOException e) {
        LOG.error("Unable to build and upload coprocessor jars.", e);
        System.exit(1);
    }
}

From source file:net.forkwait.imageautomator.ImageAutomator.java

public static void main(String[] args) throws IOException {
    String inputImage = "";

    Options options = new Options();
    options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext");
    options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97");
    options.addOption("s", true, "output max side length in px (e.g. 800), default 1200");
    options.addOption("w", true, "watermark image file");
    options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0");
    options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT");

    /*//from   ww w. j av a2 s.  c  om
    TOP_LEFT
    TOP_CENTER
    TOP_RIGHT
    CENTER_LEFT
    CENTER
    CENTER_RIGHT
    BOTTOM_LEFT
    BOTTOM_CENTER
    BOTTOM_RIGHT
     */

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
        if (cmd.getArgs().length < 1) {
            throw new ParseException("Too few arguments");
        } else if (cmd.getArgs().length > 1) {
            throw new ParseException("Too many arguments");
        }
        inputImage = cmd.getArgs()[0];
    } catch (ParseException e) {
        showHelp(options, e.getLocalizedMessage());
        System.exit(-1);
    }

    Thumbnails.Builder<File> st = Thumbnails.of(inputImage);

    if (cmd.hasOption("q")) {
        st.outputQuality(Double.parseDouble(cmd.getOptionValue("q")));
    } else {
        st.outputQuality(0.97f);
    }

    if (cmd.hasOption("s")) {
        st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s")));
    } else {
        st.size(1200, 1200);
    }
    if (cmd.hasOption("w")) {
        Positions position = Positions.BOTTOM_RIGHT;
        float trans = 0.5f;
        if (cmd.hasOption("wp")) {
            position = Positions.valueOf(cmd.getOptionValue("wp"));
        }
        if (cmd.hasOption("wt")) {
            trans = Float.parseFloat(cmd.getOptionValue("wt"));
        }

        st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans);
    }
    if (cmd.hasOption("o")) {
        st.toFile(new File(cmd.getOptionValue("o")));
    } else {
        st.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
    }

    //.outputFormat("jpg")
    System.exit(0);
}