Package org.apache.commons.cli

Examples of org.apache.commons.cli.CommandLine


    options.addOption(opt);
    opt = new Option("t", true, "capacity of the channel");
    opt.setRequired(true);
    options.addOption(opt);
    CommandLineParser parser = new GnuParser();
    CommandLine cli = parser.parse(options, args);
    File checkpointDir = new File(cli.getOptionValue("c"));
    String[] logDirs = cli.getOptionValue("l").split(",");
    List<File> logFiles = Lists.newArrayList();
    for (String logDir : logDirs) {
      logFiles.addAll(LogUtils.getLogs(new File(logDir)));
    }
    int capacity = Integer.parseInt(cli.getOptionValue("t"));
    File checkpointFile = new File(checkpointDir, "checkpoint");
    if(checkpointFile.exists()) {
      LOG.error("Cannot execute fast replay",
          new IllegalStateException("Checkpoint exists" + checkpointFile));
    } else {
View Full Code Here


        int length = 0;
        int min_bootstrap_words = NBClassifier.MIN_BOOTSTRSP_WORDS;
        boolean hideTaxon = false;
        
        try {
            CommandLine line = new PosixParser().parse(options, args);

            if (line.hasOption(QUERYFILE_SHORT_OPT)) {
                queryFile = line.getOptionValue(QUERYFILE_SHORT_OPT);
            } else {
                throw new Exception("query file must be specified");
            }
            if (line.hasOption(OUTFILE_SHORT_OPT)) {
                outputFile = line.getOptionValue(OUTFILE_SHORT_OPT);
            } else {
                throw new Exception("output file must be specified");
            }

            if (line.hasOption(TRAIN_SEQFILE_SHORT_OPT)) {
                trainSeqFile = line.getOptionValue(TRAIN_SEQFILE_SHORT_OPT);
            } else {
                throw new Exception("training sequence file must be specified");
            }
            if (line.hasOption(TRAIN_TAXONFILE_SHORT_OPT)) {
                trainTaxonFile = line.getOptionValue(TRAIN_TAXONFILE_SHORT_OPT);
            } else {
                throw new Exception("training taxon file must be specified");
            }

            if (line.hasOption(LENGTH_SHORT_OPT)) {
                length = Integer.parseInt(line.getOptionValue(LENGTH_SHORT_OPT));
                if (length <= 0) {
                    throw new IllegalArgumentException(length + " must be a positive number ");
                }
            }
            if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) {
                min_bootstrap_words = Integer.parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT));
                if (min_bootstrap_words < NBClassifier.MIN_BOOTSTRSP_WORDS) {
                    throw new IllegalArgumentException(CmdOptions.MIN_BOOTSTRAP_WORDS_LONG_OPT + " must be at least " + NBClassifier.MIN_BOOTSTRSP_WORDS);
                }               
            }
           
            if (line.hasOption(HIDETAXON_SHORT_OPT)) {
                hideTaxon = true;
            }       
            /*
            if (line.hasOption(KMER_SHORT_OPT)) {
                int kmer = Integer.parseInt(line.getOptionValue(KMER_SHORT_OPT));
View Full Code Here

        Integer partialLength = null// default is full length
        float fraction = 0.1f;
        String rdmSelectedRank = null;
        int min_bootstrap_words = NBClassifier.MIN_BOOTSTRSP_WORDS;
        try {
            CommandLine line = new PosixParser().parse(options, args);
            if (line.hasOption(TRAIN_TAXONFILE_SHORT_OPT) ) {
              tax_file = line.getOptionValue(TRAIN_TAXONFILE_SHORT_OPT);
            } else {
                throw new ParseException("Taxonomy file must be specified");
            }
            if (line.hasOption(TRAIN_SEQFILE_SHORT_OPT) ) {
              source_file = line.getOptionValue(TRAIN_SEQFILE_SHORT_OPT);
            } else {
                throw new ParseException("Source training fasta file must be specified");
            }
            if (line.hasOption(OUTFILE_SHORT_OPT) ) {
              out_file = line.getOptionValue(OUTFILE_SHORT_OPT);
            } else {
                throw new ParseException("Output file must be specified");
            }

            if (line.hasOption(LENGTH_SHORT_OPT) ) {
;              partialLength = new Integer(line.getOptionValue(LENGTH_SHORT_OPT));
            }
            if (line.hasOption("fraction") ) {
              fraction = Float.parseFloat(line.getOptionValue("fraction"));
            }
            if (line.hasOption("rdmRank") ) {
                rdmSelectedRank = line.getOptionValue("rdmRank");
            }
            if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) {
                min_bootstrap_words = Integer.parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT));
                if (min_bootstrap_words < NBClassifier.MIN_BOOTSTRSP_WORDS) {
                    throw new IllegalArgumentException(min_bootstrap_words + " must be at least " + NBClassifier.MIN_BOOTSTRSP_WORDS);
                }               
            }
           
View Full Code Here

    options.addOption(OptionBuilder.withArgName("path").hasArg()
        .withDescription("output repair file (can be used later as a data file)")
        .create(REPAIR_OPTION));
    options.addOption(NOFOLLOW_OPTION, NOFOLLOW_OPTION, false, "don't follow 301 redirects");

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
      cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
      System.err.println("Error parsing command line: " + exp.getMessage());
      System.exit(-1);
    }

    if (!cmdline.hasOption(DATA_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(AsyncHTMLStatusBlockCrawler.class.getName(), options);
      System.exit(-1);
    }

    String data = cmdline.getOptionValue(DATA_OPTION);
    String output = cmdline.getOptionValue(OUTPUT_OPTION);
    String repair = cmdline.getOptionValue(REPAIR_OPTION);
    boolean noFollow = cmdline.hasOption(NOFOLLOW_OPTION);
    new AsyncHTMLStatusBlockCrawler(new File(data), output, repair, noFollow).fetch();
  }
View Full Code Here

        PrintStream outStream = null;
        AlignmentMode mode = AlignmentMode.overlap;
        boolean show_alignment = false;
      
         try {
            CommandLine line = new PosixParser().parse(options, args);

            if (line.hasOption("show_alignment")) {
                show_alignment = true;
            }
            if (line.hasOption("alignment-mode")) {
                String m = line.getOptionValue("alignment-mode").toLowerCase();
                mode = AlignmentMode.valueOf(m);
             
            }
           
            if ( args.length != 3){
                throw new Exception("wrong arguments");
            }
            args = line.getArgs();           
            trainseqFile = args[0];
            taxFile = args[1];
            outStream = new PrintStream(new File(args[2]));
         }catch (Exception e) {
            System.err.println("Command Error: " + e.getMessage());
View Full Code Here

      Options options = getOptions();
      try {
       
        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse( options, args );
        File dir = new File(line.getOptionValue("dir", "."));
        String name = line.getOptionValue("name", "jar");
        System.out.println("total size of files in "+dir+" containing "+name+": "+SizeWhere.totalSize(dir, name));
      } catch( ParseException exp ) {
          // oops, something went wrong
          System.err.println( "Parsing failed.  Reason: " + exp.getMessage() );
         
View Full Code Here

        Options options = getOptions();
        try {
       
            CommandLineParser parser = new GnuParser();
   
            CommandLine line = parser.parse(options, args);
            File dir = new File(line.getOptionValue("dir", "."));
            String name = line.getOptionValue("name", "jar");
            Collection files = FindFile.find(dir, name);
            System.out.println("listing files in " + dir + " containing " + name);
            for (Iterator it = files.iterator(); it.hasNext();) {
                System.out.println("\t" + it.next() + "\n");
            }
View Full Code Here

      Options options = getOptions();
      try {
       
        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse( options, args );
        File dir = new File(line.getOptionValue("dir", "."));
        Collection files = ListFile.list(dir);
        System.out.println("listing files in "+dir);
        for (Iterator it = files.iterator(); it.hasNext(); ) {
          System.out.println("\t"+it.next()+"\n");
        }
View Full Code Here

    // Parse the given argument vector
    public Command parse(String[] argv) {
        CommandLineParser parser = new PosixParser();

        CommandLine cmdline = null;
        try {
            cmdline = parser.parse(this.rules, argv);
        }
        catch (ParseException e) {
            error(e.getMessage());
        }

        // Unpack the cmdline into a simple Map of options and optionally
        // assign values to any corresponding fields found in the Command class.
        for (Option option : cmdline.getOptions()) {
            String name = option.getLongOpt();
            Object value = option.getValue();
           
            // Figure out the type of the option and convert the value.
            if (!option.hasArg()) {
                // If it has no arg, then its implicitly boolean and presence
                // of the argument indicates truth.
                value = true;
            }
            else {
                Class type = (Class)option.getType();
                if (type == null) {
                    // Null implies String, no conversion necessary
                }
                else if (type == Integer.class) {
                    value = Integer.parseInt((String)value);
                }
                else {
                    assert false; // Unsupported type
                }
            }

            this.opts.put(name, value);

            // Look for a field of the Command class (or subclass) that
            // matches the long name of the option and, if found, assign the
            // corresponding option value in order to provide simplified
            // access to command options.
            try {
                java.lang.reflect.Field field = this.getClass().getField(name);
                field.set(this, value);
            }
            catch (NoSuchFieldException e) { continue; }
            catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

        String[] orig = this.args;
        String[] more = cmdline.getArgs();
        this.args = new String[orig.length + more.length];
        System.arraycopy(orig, 0, this.args, 0, orig.length);
        System.arraycopy(more, 0, this.args, orig.length, more.length);

        if (this.help) {
View Full Code Here

    // load and verify the options
    CommandLineParser parser = new PosixParser();
    Options opts = loadOptions();

    CommandLine cmd = null;
    try {
      cmd = parser.parse(opts, args);
    } catch (org.apache.commons.cli.ParseException parseEx) {
      LOG.error("Invalid option");
      printHelp(opts);
      return;
    }

    // check for necessary options
    String fileLoc = cmd.getOptionValue("schemaLocation");
    if (fileLoc == null) {
      LOG.error("schemaLocation not specified");
      printHelp(opts);
    }

    //get string length and check if min is greater than 0

    // Generate the record
    File schemaFile = new File(fileLoc);
    DataGenerator dataGenerator = new DataGenerator(schemaFile);
    GenericRecord record = dataGenerator.generateRandomRecord();
    if (cmd.hasOption(PRINT_AVRO_JSON_OPTNAME))
    {
      String outname = cmd.getOptionValue(PRINT_AVRO_JSON_OPTNAME);
      OutputStream outs = System.out;
      if (!outname.equals("-"))
      {
        outs = new FileOutputStream(outname);
      }
View Full Code Here

TOP

Related Classes of org.apache.commons.cli.CommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.