Example usage for org.apache.commons.cli PosixParser parse

List of usage examples for org.apache.commons.cli PosixParser parse

Introduction

In this page you can find the example usage for org.apache.commons.cli PosixParser parse.

Prototype

public CommandLine parse(Options options, String[] arguments) throws ParseException 

Source Link

Document

Parses the specified arguments based on the specifed Options .

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 w w w  .  j  a v a 2s . c om
        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:b2s.idea.mavenize.App.java

public static void main(String... args) throws ParseException {
    Options options = new Options();
    options.addOption("i", "idea-dir", true, "Path to root directory of an intellij instance");
    options.addOption("o", "output-dir", true, "Path to put the newly created jar");

    if (args.length == 0) {
        error("", options);
        return;//from   w w w . j  a v  a2 s.c o m
    }

    PosixParser parser = new PosixParser();
    CommandLine commandLine = parser.parse(options, args);

    if (commandLine.hasOption("i")) {
        String ideaDirValue = commandLine.getOptionValue("i");
        File ideaFolder = new File(ideaDirValue);
        if (!ideaFolder.exists()) {
            error("This path [" + ideaDirValue + "] can not be found", options);
            return;
        }

        File libFolder = new File(ideaFolder, "lib");
        if (!libFolder.exists()) {
            error("The [lib] folder was not found in the IDEA folder", options);
            return;
        }

        if (commandLine.hasOption("output-dir")) {
            File output = new File(commandLine.getOptionValue("output-dir"), determineFilename(ideaFolder));
            jarCombiner.combineAllJarsIn(libFolder, output);
            System.out.println("Combined Jar: " + output);
        } else {
            error("Please provide an output directory", options);
        }
    } else {
        error("Please provide the IDEA directory path", options);
    }
}

From source file:com.github.besherman.fingerprint.Main.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withDescription("creates a fingerprint file for the directory").hasArg()
            .withArgName("dir").create('c'));

    options.addOption(OptionBuilder.withDescription("shows a diff between two fingerprint files")
            .withArgName("left-file> <right-file").hasArgs(2).create('d'));

    options.addOption(OptionBuilder.withDescription("shows a diff between a fingerprint and a directory")
            .withArgName("fingerprint> <dir").hasArgs(2).create('t'));

    options.addOption(OptionBuilder.withDescription("shows duplicates in a directory").withArgName("dir")
            .hasArgs(1).create('u'));

    options.addOption(/* w  ww .  ja v a2 s .c o m*/
            OptionBuilder.withDescription("output to file").withArgName("output-file").hasArg().create('o'));

    PosixParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException ex) {
        System.out.println(ex.getMessage());
        System.out.println("");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("fingerprint-dir", options, true);
        System.exit(7);
    }

    if (cmd.hasOption('c')) {
        Path root = Paths.get(cmd.getOptionValue('c'));

        if (!Files.isDirectory(root)) {
            System.err.println("root is not a directory");
            System.exit(7);
        }

        OutputStream out = System.out;

        if (cmd.hasOption('o')) {
            Path p = Paths.get(cmd.getOptionValue('o'));
            out = Files.newOutputStream(p);
        }

        Fingerprint fp = new Fingerprint(root, "");
        fp.write(out);

    } else if (cmd.hasOption('d')) {
        String[] ar = cmd.getOptionValues('d');
        Path leftFingerprintFile = Paths.get(ar[0]), rightFingerprintFile = Paths.get(ar[1]);
        if (!Files.isRegularFile(leftFingerprintFile)) {
            System.out.printf("%s is not a file%n", leftFingerprintFile);
            System.exit(7);
        }
        if (!Files.isRegularFile(rightFingerprintFile)) {
            System.out.printf("%s is not a file%n", rightFingerprintFile);
            System.exit(7);
        }

        Fingerprint left, right;
        try (InputStream input = Files.newInputStream(leftFingerprintFile)) {
            left = new Fingerprint(input);
        }

        try (InputStream input = Files.newInputStream(rightFingerprintFile)) {
            right = new Fingerprint(input);
        }

        Diff diff = new Diff(left, right);

        // TODO: if we have redirected output
        diff.print(System.out);
    } else if (cmd.hasOption('t')) {
        throw new RuntimeException("Not yet implemented");
    } else if (cmd.hasOption('u')) {
        Path root = Paths.get(cmd.getOptionValue('u'));
        Fingerprint fp = new Fingerprint(root, "");
        Map<String, FilePrint> map = new HashMap<>();
        fp.stream().forEach(f -> {
            if (map.containsKey(f.getHash())) {
                System.out.println("  " + map.get(f.getHash()).getPath());
                System.out.println("= " + f.getPath());
                System.out.println("");
            } else {
                map.put(f.getHash(), f);
            }
        });
    } else {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("fingd", options, true);
    }
}

From source file:com.genentech.chemistry.tool.sdf2DAlign.java

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

    final String OPT_INFILE = "in";
    final String OPT_OUTFILE = "out";
    final String OPT_TEMPLATEFILE = "templates";
    final String OPT_RESETCOORDS = "reset";
    final String OPT_DEBUG = "debug";

    Options options = new Options();

    Option opt = new Option(OPT_INFILE, true, "Input file (oe-supported). Use .sdf to specify the file type.");
    opt.setRequired(true);//from   www  .j  a  v a 2s .co  m
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "Output file (oe-supported). Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_TEMPLATEFILE, true,
            "Template file (oe-supported). Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_RESETCOORDS, false,
            "Reset coordinates in input file when aligning. This will delete original 2D coords and create new ones.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_DEBUG, false, "Print debug statements.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("h", false, "print usage statement");
    opt.setRequired(false);
    options.addOption(opt);

    PosixParser parser = new PosixParser();
    CommandLine cl = null;

    try {
        cl = parser.parse(options, args);
    } catch (Exception exp) {
        System.err.println(exp.getMessage());
        exitWithHelp(options);
    }

    //get command line parameters
    String inFile = cl.getOptionValue(OPT_INFILE);
    String outFile = cl.getOptionValue(OPT_OUTFILE);
    String templateFile = cl.getOptionValue(OPT_TEMPLATEFILE);
    boolean resetCoords = cl.hasOption(OPT_RESETCOORDS);
    boolean debug = cl.hasOption(OPT_DEBUG);

    sdf2DAlign myAlign = new sdf2DAlign(inFile, outFile, templateFile, resetCoords);
    myAlign.setDebug(debug);

    //get templates as subsearches
    List<OESubSearch> templates = myAlign.getTemplates();

    //apply template to input molecules
    myAlign.applyTemplates(templates);

    for (OESubSearch ss : templates)
        ss.delete();
}

From source file:com.denimgroup.threadfix.cli.CommandLineParser.java

public static void main(String[] args) {

    Options options = getOptions();/*from  w w  w. j a  v  a  2s.  c  o m*/

    PosixParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar tfcli.jar", options);

        } else if (cmd.hasOption("s")) {

            String[] setArgs = cmd.getOptionValues("s");
            if (setArgs == null || setArgs.length != 2) {
                throw new ParseException("Bad arguments for set.");
            }

            if ("url".equals(setArgs[0])) {
                System.out.println("Setting URL to " + setArgs[1]);
                client.setUrl(setArgs[1]);
            } else if ("key".equals(setArgs[0])) {
                System.out.println("Setting API Key to " + setArgs[1]);
                client.setKey(setArgs[1]);
            } else {
                throw new ParseException("First argument to set must be url or key");
            }

        } else if (cmd.hasOption("ct")) {
            String[] createArgs = cmd.getOptionValues("ct");
            if (createArgs.length != 1) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Creating a Team with the name " + createArgs[0] + ".");
            System.out.println(client.createTeam(createArgs[0]));

        } else if (cmd.hasOption("cw")) {
            String[] createArgs = cmd.getOptionValues("cw");
            if (createArgs.length != 2) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Creating a Waf with the name " + createArgs[0] + ".");
            System.out.println(client.createWaf(createArgs[0], createArgs[1]));

        } else if (cmd.hasOption("ca")) {
            String[] createArgs = cmd.getOptionValues("ca");
            if (createArgs.length != 3) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Creating an Application with the name " + createArgs[1] + ".");
            System.out.println(client.createApplication(createArgs[0], createArgs[1], createArgs[2]));

        } else if (cmd.hasOption("teams")) {
            System.out.println("Getting all teams.");
            System.out.println(client.getAllTeams());

        } else if (cmd.hasOption("u")) {
            String[] uploadArgs = cmd.getOptionValues("u");
            // Upload a scan
            if (uploadArgs.length != 2) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Uploading " + uploadArgs[1] + " to Application " + uploadArgs[0] + ".");
            System.out.println(client.uploadScan(uploadArgs[0], uploadArgs[1]));

        } else if (cmd.hasOption("st")) {
            String[] searchArgs = cmd.getOptionValues("st");
            if (searchArgs.length != 2) {
                throw new ParseException("Wrong number of arguments.");
            }
            if ("id".equals(searchArgs[0])) {
                System.out.println("Searching for team with the id " + searchArgs[1] + ".");
                System.out.println(client.searchForTeamById(searchArgs[1]));
            } else if ("name".equals(searchArgs[0])) {
                System.out.println("Searching for team with the name " + searchArgs[1] + ".");
                System.out.println(client.searchForTeamByName(searchArgs[1]));
            } else {
                System.out.println("Unknown property argument. Try either id or name.");
                return;
            }

        } else if (cmd.hasOption("sw")) {
            String[] searchArgs = cmd.getOptionValues("sw");
            if (searchArgs.length != 4) {
                throw new ParseException("Wrong number of arguments.");
            }
            if ("id".equals(searchArgs[0])) {
                System.out.println("Searching for WAF with the id " + searchArgs[1] + ".");
                System.out.println(client.searchForWafById(searchArgs[1]));
            } else if ("name".equals(searchArgs[0])) {
                System.out.println("Searching for WAF with the name " + searchArgs[1] + ".");
                System.out.println(client.searchForWafByName(searchArgs[1]));
            } else {
                throw new ParseException("Unknown property argument. Try either id or name.");
            }

        } else if (cmd.hasOption("sa")) {
            String[] searchArgs = cmd.getOptionValues("sa");
            if ("id".equals(searchArgs[0])) {
                if (searchArgs.length != 2) {
                    System.out.println("Wrong number of arguments.");
                    return;
                }
                System.out.println("Searching for application with the id " + searchArgs[1] + ".");
                System.out.println(client.searchForApplicationById(searchArgs[1]));
            } else if ("name".equals(searchArgs[0])) {
                if (searchArgs.length != 3) {
                    System.out.println(
                            "Wrong number of arguments. You need to input application name and team name as well.");
                    return;
                }
                System.out.println("Searching for application with the name " + searchArgs[1] + " of team "
                        + searchArgs[2]);
                System.out.println(client.searchForApplicationByName(searchArgs[1], searchArgs[2]));
            } else {
                System.out.println("Unknown property argument. Try either id or name.");
                return;
            }

        } else if (cmd.hasOption("r")) {
            String[] ruleArgs = cmd.getOptionValues("r");
            if (ruleArgs.length != 1) {
                System.out.println("Wrong number of arguments.'");
            }
            System.out.println("Downloading rules from WAF with ID " + ruleArgs[0] + ".");
            System.out.println(client.getRules(ruleArgs[0]));

        } else {
            throw new ParseException("No arguments found.");
        }

    } catch (ParseException e) {
        if (e.getMessage() != null) {
            System.out.println(e.getMessage());
        }
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar tfcli.jar", options);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.flow.instances.ofa.OFAXMLizerCLI.java

/**
 * The entry point to the program via command line.
 * //from w  w  w .ja v a  2  s  . c o  m
 * @param args is the command line arguments.
 * @throws RuntimeException when object flow analysis fails.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("c", "cumulative", false, "Consider all root methods in the same execution.");
    _options.addOption(_option);
    _option = new Option("o", "output", true, "Directory into which xml files will be written into.");
    _option.setArgs(1);
    _options.addOption(_option);
    _option = new Option("j", "jimple", false, "Dump xmlized jimple.");
    _options.addOption(_option);
    _option = new Option("h", "help", false, "Display message.");
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("t", "ofa-type", false, "Type of analysis : fioi, fsoi, fios, fsos, fioirt, fsoirt.");
    _option.setArgs(1);
    _option.setArgName("type");
    _option.setOptionalArg(false);
    _option.setRequired(true);
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final PosixParser _parser = new PosixParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            printUsage(_options);
            System.exit(1);
        }

        String _outputDir = _cl.getOptionValue('o');

        if (_outputDir == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Defaulting to current directory for output.");
            }
            _outputDir = ".";
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final OFAXMLizerCLI _cli = new OFAXMLizerCLI();
        _cli.xmlizer.setXmlOutputDir(_outputDir);
        _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator());
        _cli.setCumulative(_cl.hasOption('c'));
        _cli.setClassNames(_cl.getArgList());
        _cli.type = _cl.getOptionValue('t');

        if (_cl.hasOption('p')) {
            _cli.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _cli.initialize();

        _cli.<ITokens>execute(_cl.hasOption('j'));
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line. \n" + _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.callgraphs.CallGraphXMLizerCLI.java

/**
 * The entry point to the program via command line.
 * /*w  w w  . j av  a2s. com*/
 * @param args is the command line arguments.
 * @throws RuntimeException when the analyses fail.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("c", "cumulative", false,
            "Builds one call graph that includes all root methods.");
    _options.addOption(_option);
    _option = new Option("o", "output", true,
            "Directory into which xml files will be written into.  Defaults to current directory if omitted");
    _option.setArgs(1);
    _option.setArgName("output-dir");
    _options.addOption(_option);
    _option = new Option("j", "jimple", false, "Dump xmlized jimple.");
    _option.setArgName("dump-jimple");
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", true, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("t", "call-graph-type", true,
            "Call graph type.  This has to be one of {cha, rta, ofa-oi, " + "ofa-oirt, ofa-os}.");
    _option.setArgs(1);
    _option.setArgName("type");
    _option.setRequired(true);
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final PosixParser _parser = new PosixParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption('h')) {
            printUsage(_options);
            System.exit(1);
        }

        String _outputDir = _cl.getOptionValue('o');

        if (_outputDir == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Defaulting to current directory for output.");
            }
            _outputDir = ".";
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final CallGraphXMLizerCLI _cli = new CallGraphXMLizerCLI();

        _cli.xmlizer.setXmlOutputDir(_outputDir);
        _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator());
        _cli.setCumulative(_cl.hasOption('c'));
        _cli.setClassNames(_cl.getArgList());
        _cli.addToSootClassPath(_cl.getOptionValue('p'));

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _cli.initialize();

        _cli.execute(_cl.hasOption('j'), _cl.getOptionValue('t'));
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:com.intuit.s3encrypt.S3Encrypt.java

public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {

    // create Options object
    Options options = new Options();
    options.addOption(create_bucket);/*from   w w w .  ja v a  2  s  .  c  om*/
    options.addOption(create_key);
    options.addOption(delete_bucket);
    options.addOption(get);
    options.addOption(help);
    options.addOption(inspect);
    options.addOption(keyfile);
    options.addOption(list_buckets);
    options.addOption(list_objects);
    options.addOption(put);
    options.addOption(remove);
    options.addOption(rotate);
    options.addOption(rotateall);
    options.addOption(rotateKey);

    //      CommandLineParser parser = new GnuParser();
    //       Changed from above GnuParser to below PosixParser because I found code which allows for multiple arguments 
    PosixParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
        Logger.getRootLogger().setLevel(Level.OFF);

        if (cmd.hasOption("help")) {
            HelpFormatter help = new HelpFormatter();
            System.out.println();
            help.printHelp("S3Encrypt", options);
            System.out.println();
            System.exit(1);
        } else if (cmd.hasOption("create_key")) {
            keyname = cmd.getOptionValue("keyfile");
            createKeyFile(keyname);
            key = new File(keyname);
        } else {
            if (cmd.hasOption("keyfile")) {
                keyname = cmd.getOptionValue("keyfile");
            }
            key = new File(keyname);
        }

        if (!(key.exists())) {
            System.out.println("Key does not exist or not provided");
            System.exit(1);
        }

        //         AmazonS3 s3 = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());
        ClasspathPropertiesFileCredentialsProvider credentials = new ClasspathPropertiesFileCredentialsProvider(
                ".s3encrypt");
        EncryptionMaterials encryptionMaterials = new EncryptionMaterials(getKeyFile(keyname));
        AmazonS3EncryptionClient s3 = new AmazonS3EncryptionClient(credentials.getCredentials(),
                encryptionMaterials);
        //          Region usWest2 = Region.getRegion(Regions.US_WEST_2);
        //          s3.setRegion(usWest2);

        if (cmd.hasOption("create_bucket")) {
            String bucket = cmd.getOptionValue("create_bucket");
            System.out.println("Creating bucket " + bucket + "\n");
            s3.createBucket(bucket);
        } else if (cmd.hasOption("delete_bucket")) {
            String bucket = cmd.getOptionValue("delete_bucket");
            System.out.println("Deleting bucket " + bucket + "\n");
            s3.deleteBucket(bucket);
        } else if (cmd.hasOption("get")) {
            String[] searchArgs = cmd.getOptionValues("get");
            String bucket = searchArgs[0];
            String filename = searchArgs[1];
            getS3Object(cmd, s3, bucket, filename);
        } else if (cmd.hasOption("inspect")) {
            String[] searchArgs = cmd.getOptionValues("inspect");
            String bucket = searchArgs[0];
            String filename = searchArgs[1];
            String keyname = "encryption_key";
            String metadata = inspectS3Object(cmd, s3, bucket, filename, keyname);
            System.out.println(metadata);
        } else if (cmd.hasOption("list_buckets")) {
            System.out.println("Listing buckets");
            for (Bucket bucket : s3.listBuckets()) {
                System.out.println(bucket.getName());
            }
            System.out.println();
        } else if (cmd.hasOption("list_objects")) {
            String bucket = cmd.getOptionValue("list_objects");
            System.out.println("Listing objects");
            ObjectListing objectListing = s3.listObjects(new ListObjectsRequest().withBucketName(bucket));
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                System.out.println(objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
            }
            System.out.println();
        } else if (cmd.hasOption("put")) {
            String[] searchArgs = cmd.getOptionValues("put");
            String bucket = searchArgs[0];
            String filename = searchArgs[1];
            String metadataKeyname = "encryption_key";
            String key = keyname;
            putS3Object(cmd, s3, bucket, filename, metadataKeyname, key);
        } else if (cmd.hasOption("remove")) {
            String[] searchArgs = cmd.getOptionValues("remove");
            String bucket = searchArgs[0];
            String filename = searchArgs[1];
            System.out.println("Removing object in S3 from BUCKET = " + bucket + " FILENAME = " + filename);
            s3.deleteObject(new DeleteObjectRequest(bucket, filename));
            System.out.println();
        } else if (cmd.hasOption("rotate")) {
            String[] searchArgs = cmd.getOptionValues("rotate");
            String bucket = searchArgs[0];
            String filename = searchArgs[1];
            String key1 = cmd.getOptionValue("keyfile");
            String key2 = cmd.getOptionValue("rotateKey");
            String metadataKeyname = "encryption_key";
            System.out.println("Supposed to get object from here OPTION VALUE = " + bucket + " FILENAME = "
                    + filename + " KEY1 = " + key1 + " KEY2 = " + key2);

            EncryptionMaterials rotateEncryptionMaterials = new EncryptionMaterials(getKeyFile(key2));
            AmazonS3EncryptionClient rotateS3 = new AmazonS3EncryptionClient(credentials.getCredentials(),
                    rotateEncryptionMaterials);

            getS3Object(cmd, s3, bucket, filename);
            putS3Object(cmd, rotateS3, bucket, filename, metadataKeyname, key2);
        } else if (cmd.hasOption("rotateall")) {
            String[] searchArgs = cmd.getOptionValues("rotateall");
            String bucket = searchArgs[0];
            String key1 = searchArgs[1];
            String key2 = searchArgs[2];
            System.out.println("Supposed to rotateall here for BUCKET NAME = " + bucket + " KEY1 = " + key1
                    + " KEY2 = " + key2);
        } else {
            System.out.println("Something went wrong... ");
            System.exit(1);
        }

    } catch (ParseException e) {
        e.printStackTrace();
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " + "means the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}

From source file:com.genentech.chemistry.tool.SDFBinning.java

private static void processOptions(String[] args) {
    Options options = new Options();

    Option opt = new Option("in", true, "Input file oe-supported Use .sdf to specify the file type.");
    opt.setRequired(true);//  w  w  w. ja v  a  2 s  .co  m
    options.addOption(opt);

    opt = new Option("out", true, "Output file oe-supported Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("bin", true,
            "bin definition. Use format \"bin_1_upperbound=bin_1_name|bin_2_upperbound=bin_2_name|bin_3_upperbound_=bin_3_name\"");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("dataTag", true, "SD tag containing data for binning");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("binTag", true, "SD tag used for storing bin names");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("ignoreModifier", false, "ignore leading '><= ~'");
    options.addOption(opt);

    opt = new Option("h", false, "print usage statement");
    opt.setRequired(false);
    options.addOption(opt);

    PosixParser parser = new PosixParser();
    CommandLine cl = null;

    try {
        cl = parser.parse(options, args);
    } catch (Exception exp) {
        // catch (ParseException exp) {
        System.err.println(exp.getMessage());
        exitWithHelp(options);
    }
    inFile = cl.getOptionValue("in");
    outFile = cl.getOptionValue("out");
    ignoreModifier = cl.hasOption("ignoreModifier");
    String binDefinition = cl.getOptionValue("bin");
    parseBins(binDefinition);

    binTag = cl.getOptionValue("binTag");
    dataTag = cl.getOptionValue("dataTag");
}

From source file:com.cloudera.beeswax.Server.java

/**
 * Parse command line options./* ww w  . j a v  a2s  .  c  o  m*/
 *
 * -b <port> specifies the port for beeswax to use.
 * -m <port>, if given, starts the metastore at this port.
 */
private static void parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    Option metastoreOpt = new Option("m", "metastore", true, "port to use for metastore");
    metastoreOpt.setRequired(false);
    options.addOption(metastoreOpt);

    Option beeswaxOpt = new Option("b", "beeswax", true, "port to use for beeswax");
    beeswaxOpt.setRequired(true);
    options.addOption(beeswaxOpt);

    Option dtHostOpt = new Option("h", "desktop-host", true, "host running desktop");
    dtHostOpt.setRequired(true);
    options.addOption(dtHostOpt);

    Option dtHttpsOpt = new Option("s", "desktop-https", true, "desktop is running https");
    options.addOption(dtHttpsOpt);

    Option dtPortOpt = new Option("p", "desktop-port", true, "port used by desktop");
    dtPortOpt.setRequired(true);
    options.addOption(dtPortOpt);

    Option superUserOpt = new Option("u", "superuser", true, "Username of Hadoop superuser (default: hadoop)");
    superUserOpt.setRequired(false);
    options.addOption(superUserOpt);

    PosixParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    if (!cmd.getArgList().isEmpty()) {
        throw new ParseException("Unexpected extra arguments: " + cmd.getArgList());
    }

    for (Option opt : cmd.getOptions()) {
        if (opt.getOpt() == "m") {
            mport = parsePort(opt);
        } else if (opt.getOpt() == "b") {
            bport = parsePort(opt);
        } else if (opt.getOpt() == "u") {
            superUser = opt.getValue();
        } else if (opt.getOpt() == "h") {
            dtHost = opt.getValue();
        } else if (opt.getOpt() == "p") {
            dtPort = parsePort(opt);
        } else if (opt.getOpt() == "s") {
            dtHttps = true;
        }
    }
}