Package org.apache.commons.cli

Examples of org.apache.commons.cli.ParseException


        if ("protobuf".equals(eng)) {
          rpcEngine = ProtobufRpcEngine.class;
        } else if ("writable".equals(eng)) {
          rpcEngine = WritableRpcEngine.class;
        } else {
          throw new ParseException("invalid engine: " + eng);
        }
      }
     
      String[] remainingArgs = line.getArgs();
      if (remainingArgs.length != 0) {
        throw new ParseException("Extra arguments: " +
            Joiner.on(" ").join(remainingArgs));
      }
    }
View Full Code Here


  private void checkDependencies() throws ParseException {
    Preconditions.checkNotNull(cmdline, "Command line arguments not parsed yet!");

    for(Object option: options.getRequiredOptions()) {
      if(!cmdline.hasOption((String) option)) {
        throw new ParseException("Option \"" + option + "\" not found.");
      }
    }

    for(String optionA: dependencies.keySet()) {
      if(!cmdline.hasOption(optionA)) {
        continue;
      }
      for(String optionB: dependencies.get(optionA)) {
        if(!cmdline.hasOption(optionB)) {
          throw new ParseException("Option \"" + optionB + "\" not found.");
        }
      }
    }
  }
View Full Code Here

            format = cmd.getOptionValue('f');
            final RDFFormat fmt;
            if (format != null) {
                fmt = RDFFormat.forMIMEType(format);
                if (fmt == null) {
                    throw new ParseException(String.format("Invalid/Unknown RDF format: %s, use one of %s", format, RDFFormat.values()));
                }
                log.debug("Format-Hint: {}", fmt);
            } else {
                fmt = null;
            }

            // get the files to import.
            final ArrayList<String> inputFiles = new ArrayList<String>();
            // - provided with the -i option
            if (cmd.hasOption('i')) {
                inputFiles.addAll(Arrays.asList(cmd.getOptionValues('i')));
            }
            // - or just the filename.
            inputFiles.addAll(Arrays.asList(cmd.getArgs()));

            // we need at least one file to import
            // this could be changed...
            if (inputFiles.isEmpty()) {
                throw new ParseException("No files to import");
            }

            // initialize the KiWiLoader
            log.info("Initializing KiWiLoader for {}; user: {}, password: {}", dbCon, dbUser, String.format("%"+dbPasswd.length()+"s", "*"));
            KiWiLoader loader = new KiWiLoader(kiwi, baseUri, context);
View Full Code Here

            if (cmd.getOptionValue('P') != null) {
                return cmd.getOptionValue('P');
            } else {
                Console console = System.console();
                if (console == null) {
                    throw new ParseException("Could not aquire console, please provide password as parameter");
                }

                char passwordArray[] = console.readPassword("Password for %s on %s: ", jdbc, user);
                return new String(passwordArray);
            }
View Full Code Here

            } else if (dbCon.startsWith("jdbc:mysql:")) {
                return new MySQLDialect();
            } else if (dbCon.startsWith("jdbc:postgresql:")) {
                return new PostgreSQLDialect();
            } else {
                throw new ParseException("could not guess dialect from url, use the -D option");
            }
        } else if ("h2".equalsIgnoreCase(dbDialect)) {
            return new H2Dialect();
        } else if ("mysql".equalsIgnoreCase(dbDialect)) {
            return new MySQLDialect();
        } else if ("postgresql".equalsIgnoreCase(dbDialect)) {
            return new PostgreSQLDialect();
        } else {
            throw new ParseException("Unknown dialect: " + dbDialect);
        }
    }
View Full Code Here

      GnuParser parser = new GnuParser();
      CommandLine cmd = null;
      try {
        cmd = parser.parse(options, args);
        if (cmd.getArgs().length != 0) {
          throw new ParseException("Command takes no arguments");
        }
      } catch (ParseException e) {
        System.err.println("Failed to parse command line " + e.getMessage());
        System.err.println();
        HelpFormatter formatter = new HelpFormatter();
View Full Code Here

      GnuParser parser = new GnuParser();
      CommandLine cmd = null;
      try {
        cmd = parser.parse(options, args);
        if (cmd.getArgs().length != 0) {
          throw new ParseException("Command takes no arguments");
        }
      } catch (ParseException e) {
        System.err.println("Failed to parse command line " + e.getMessage());
        System.err.println();
        HelpFormatter formatter = new HelpFormatter();
View Full Code Here

    GnuParser parser = new GnuParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, args);
      if (cmd.getArgs().length != 2) {
        throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length);
      }
    } catch (ParseException e) {
      System.err.println("Failed to parse command line " + e.getMessage());
      System.err.println();
      HelpFormatter formatter = new HelpFormatter();
View Full Code Here

    GnuParser parser = new GnuParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, args);
      if (cmd.getArgs().length != 2) {
        throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length);
      }
    } catch (ParseException e) {
      System.err.println("Failed to parse command line " + e.getMessage());
      System.err.println();
      HelpFormatter formatter = new HelpFormatter();
View Full Code Here

      return false;
    }

    if (commandLine.hasOption("filename") && commandLine.hasOption("dirname")) {
      throw new ParseException(
          "--filename and --dirname options cannot be used simultaneously");
    }

    if (!commandLine.hasOption("port") && !commandLine.hasOption("host") &&
        !commandLine.hasOption("rpcProps")) {
      throw new ParseException("Either --rpcProps or both --host and --port " +
          "must be specified.");
    }

    if (commandLine.hasOption("rpcProps")) {
      rpcClientPropsFile = commandLine.getOptionValue("rpcProps");
      Preconditions.checkNotNull(rpcClientPropsFile, "RPC client properties " +
          "file must be specified after --rpcProps argument.");
      Preconditions.checkArgument(new File(rpcClientPropsFile).exists(),
          "RPC client properties file %s does not exist!", rpcClientPropsFile);
    }

    if (rpcClientPropsFile == null) {
      if (!commandLine.hasOption("port")) {
        throw new ParseException(
            "You must specify a port to connect to with --port");
      }
      port = Integer.parseInt(commandLine.getOptionValue("port"));

      if (!commandLine.hasOption("host")) {
        throw new ParseException(
            "You must specify a hostname to connect to with --host");
      }
      hostname = commandLine.getOptionValue("host");
    }
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.