Package org.apache.commons.cli

Examples of org.apache.commons.cli.ParseException


    }

    private void validateOptions() throws ParseException {
      if (!compress.equals("none") && !compress.equals("lzo")
          && !compress.equals("gz")) {
        throw new ParseException("Unknown compression scheme: " + compress);
      }

      if (minKeyLen >= maxKeyLen) {
        throw new ParseException(
            "Max key length must be greater than min key length.");
      }

      if (minValLength >= maxValLength) {
        throw new ParseException(
            "Max value length must be greater than min value length.");
      }

      if (minWordLen >= maxWordLen) {
        throw new ParseException(
            "Max word length must be greater than min word length.");
      }
      return;
    }
View Full Code Here


      String file = cmd.getOptionValue("f");

      Filter filter;

      if (file == null) {
        throw new ParseException("No input data file specified");
      }

      if (selector == null) {
        filter = null;
      } else if (selector.equalsIgnoreCase("MI")) {
        filter = new MutualInformation();
      } else if (selector.equalsIgnoreCase("IG")) {
        filter = new InformationGain();
      } else if (selector.equalsIgnoreCase("CHI")) {
        filter = new ChiSquare();
      } else if (selector.equalsIgnoreCase("OR")) {
        filter = new OddsRatio();
      } else if (selector.equalsIgnoreCase("RS")) {
        filter = new RelevancyScore();
      } else
        throw new ParseException("Incorrect metric speficied");

      List<Review> data = null;
      IDataConn dataConn = new CsvConn(file);
      if (cmd.hasOption("d")) {
        try {
          String size = cmd.getOptionValue("d");
          data = dataConn.getReviewsNo(Integer.parseInt(size));
        } catch (NumberFormatException e) {
          throw new ParseException("Incorrect data size specified");
        }
      } else {
        data = dataConn.getReviews();
      }
View Full Code Here

  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws ParseException, KeeperException, InterruptedException,
      IOException {
    Instance instance = shellState.getInstance();
    String[] args = cl.getArgs();
    if (args.length <= 0) {
      throw new ParseException("Must provide a command to execute");
    }
    String cmd = args[0];
    boolean failedCommand = false;
   
    AdminUtil<FateCommand> admin = new AdminUtil<FateCommand>(false);
   
    String path = ZooUtil.getRoot(instance) + Constants.ZFATE;
    String masterPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_LOCK;
    IZooReaderWriter zk = getZooReaderWriter(shellState.getInstance(), cl.getOptionValue(secretOption.getOpt()));
    ZooStore<FateCommand> zs = new ZooStore<FateCommand>(path, zk);
   
    if ("fail".equals(cmd)) {
      if (args.length <= 1) {
        throw new ParseException("Must provide transaction ID");
      }
      for (int i = 1; i < args.length; i++) {
        if (!admin.prepFail(zs, zk, masterPath, args[i])) {
          System.out.printf("Could not fail transaction: %s%n", args[i]);
          failedCommand = true;
        }
      }
    } else if ("delete".equals(cmd)) {
      if (args.length <= 1) {
        throw new ParseException("Must provide transaction ID");
      }
      for (int i = 1; i < args.length; i++) {
        if (admin.prepDelete(zs, zk, masterPath, args[i])) {
          admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, args[i]);
        } else {
          System.out.printf("Could not delete transaction: %s%n", args[i]);
          failedCommand = true;
        }
      }
    } else if ("list".equals(cmd) || "print".equals(cmd)) {
      // Parse transaction ID filters for print display
      Set<Long> filterTxid = null;
      if (args.length >= 2) {
        filterTxid = new HashSet<Long>(args.length);
        for (int i = 1; i < args.length; i++) {
          try {
            Long val = Long.parseLong(args[i], 16);
            filterTxid.add(val);
          } catch (NumberFormatException nfe) {
            // Failed to parse, will exit instead of displaying everything since the intention was to potentially filter some data
            System.out.printf("Invalid transaction ID format: %s%n", args[i]);
            return 1;
          }
        }
      }
     
      // Parse TStatus filters for print display
      EnumSet<TStatus> filterStatus = null;
      if (cl.hasOption(statusOption.getOpt())) {
        filterStatus = EnumSet.noneOf(TStatus.class);
        String[] tstat = cl.getOptionValues(statusOption.getOpt());
        for (int i = 0; i < tstat.length; i++) {
          try {
            filterStatus.add(TStatus.valueOf(tstat[i]));
          } catch (IllegalArgumentException iae) {
            System.out.printf("Invalid transaction status name: %s%n", tstat[i]);
            return 1;
          }
        }
      }
     
      StringBuilder buf = new StringBuilder(8096);
      Formatter fmt = new Formatter(buf);
      admin.print(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, fmt, filterTxid, filterStatus);
      shellState.printLines(Collections.singletonList(buf.toString()).iterator(), true);
    } else {
      throw new ParseException("Invalid command option");
    }
   
    return failedCommand ? 1 : 0;
  }
View Full Code Here

   
    try {
      fs = FileSystem.get(CachedConfiguration.getInstance());
      commandLine = new BasicParser().parse(opts, args);
      if (commandLine.getArgs().length != 0)
        throw new ParseException("Extraneous arguments");
     
      safemode = commandLine.hasOption(optSafeMode.getOpt());
      offline = commandLine.hasOption(optOffline.getOpt());
      verbose = commandLine.hasOption(optVerboseMode.getOpt());
      address = commandLine.getOptionValue(optAddress.getOpt());
View Full Code Here

   
    CommandLine cl;
    try {
      cl = new BasicParser().parse(opts, args);
      if (cl.getArgs().length > 0)
        throw new ParseException("Unrecognized arguments: " + cl.getArgList());
     
      if (cl.hasOption(helpOpt.getOpt())) {
        configError = true;
        printHelp("shell", SHELL_DESCRIPTION, opts);
        return;
View Full Code Here

    boolean force = false;
   
    try {
      cl = new BasicParser().parse(opts, args);
      if (cl.hasOption("?"))
        throw new ParseException("help requested");
      args = cl.getArgs();
     
      user = cl.hasOption("u") ? cl.getOptionValue("u") : "root";
      pass = cl.hasOption("p") ? cl.getOptionValue("p").getBytes() : null;
      force = cl.hasOption("f");
     
      if (!((cl.getArgs().length == 1 && (args[0].equalsIgnoreCase("stopMaster") || args[0].equalsIgnoreCase("stopAll"))) || (cl.getArgs().length == 2 && args[0]
          .equalsIgnoreCase("stop"))))
        throw new ParseException("Incorrect arguments");
     
    } catch (ParseException e) {
      // print to the log and to stderr
      if (cl == null || !cl.hasOption("?"))
        log.error(e, e);
View Full Code Here

   
    CommandLine cl;
    try {
      cl = new BasicParser().parse(opts, args);
      if (cl.getArgs().length > 0)
        throw new ParseException("Unrecognized arguments: " + cl.getArgList());
     
      if (cl.hasOption(helpOpt.getOpt())) {
        configError = true;
        printHelp("shell", SHELL_DESCRIPTION, opts);
        return;
View Full Code Here

    CommandLine cli;
    try {
      cli = parser.parse(opts, args);
     
      if(cli.hasOption('?')){
        throw new ParseException(null);
      }
   
      if (validateDate(cli.getOptionValue('d')) &&
          validateDate(cli.getOptionValue('e'))) {
       
        if(log.isInfoEnabled()){
          StringBuffer arginfo = new StringBuffer("\n");
          arginfo.append("generate-clusters: " + cli.hasOption('g') + "\n");
          arginfo.append("calc-features: " + cli.hasOption('f') + "\n");
          arginfo.append("calc-similarity: " + cli.hasOption('s') + "\n");
          arginfo.append("classify-clusters: " + cli.hasOption('c') + "\n");
          arginfo.append("start-date: " + cli.getOptionValue('d') + "\n");
          arginfo.append("end-date: " + cli.getOptionValue('e') + "\n");
          log.info(arginfo.toString());
        }
       
        try{
          boolean clus = true, feat = true, simil = true, clas = true;
          if(cli.hasOption('g') || cli.hasOption('f')
              || cli.hasOption('s') || cli.hasOption('c')){
            if(!cli.hasOption('g')){
              clus = false;
            }
            if(!cli.hasOption('f')){
              feat = false;
            }
            if(!cli.hasOption('s')){
              simil = false;
            }
            if(!cli.hasOption('c')){
              clas = false;
            }
          }
         
          DBInterfaceFactory.init();
          SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
          Date logdate = df.parse(cli.getOptionValue('d'));
          long startTime = logdate.getTime() / 1000;
          long endTime = df.parse(cli.getOptionValue('e')).getTime() / 1000;
         
          if(clus){
            ClusterGenerator cg = new ClusterGenerator();
            List<DomainCluster> clusters = cg.generateClusters(startTime,
                endTime, true);
            cg.storeClusters(clusters, logdate);
          }
          if(feat){
            FeatureCalculator calc = new FeatureCalculator();
            calc.updateFeatures(logdate);
          }
          if(simil){
            ClusterSimilarityCalculator calc2 = new ClusterSimilarityCalculator();
            calc2.updateClusterSimilarities(logdate);
          }
          if(clas){
            Classifier calc3 = new Classifier();
            calc3.updateClusterClasses(logdate, 30);
         
        } catch (Exception e) {
          if(log.isFatalEnabled()){
            log.fatal("", e);
          }
        } finally {
          DBInterfaceFactory.shutdown();
        }
      } else {
        throw new ParseException(null);
      }
    } catch (ParseException e1){
      PrintWriter writer = new PrintWriter(System.out)
      HelpFormatter usageFormatter = new HelpFormatter();
      usageFormatter.printHelp(writer,
View Full Code Here

    opts.addOption(optAddress);
   
    try {
      commandLine = new BasicParser().parse(opts, args);
      if (commandLine.getArgs().length != 0)
        throw new ParseException("Extraneous arguments");
     
      safemode = commandLine.hasOption(optSafeMode.getOpt());
      offline = commandLine.hasOption(optOffline.getOpt());
      verbose = commandLine.hasOption(optVerboseMode.getOpt());
      address = commandLine.getOptionValue(optAddress.getOpt());
View Full Code Here

        reader.printNewline();
        return;
      } // user canceled
     
      if (cl.getArgs().length != 0)
        throw new ParseException("Unrecognized arguments: " + cl.getArgList());
     
    } catch (ParseException e) {
      PrintWriter pw = new PrintWriter(System.err);
      new HelpFormatter().printHelp(pw, Integer.MAX_VALUE, "accumulo " + VerifyTabletAssignments.class.getName(), null, opts, 2, 5, null, true);
      pw.flush();
View Full Code Here

TOP

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

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.