Examples of Getopt


Examples of gnu.getopt.Getopt

    LongOpt[] lopts =
      {
        new LongOpt("noprefix", LongOpt.NO_ARGUMENT, null, 0x1000),
      };

    Getopt getopt = new Getopt(null, args, sopts, lopts);
    getopt.setOpterr(false);

    int code;
    int argidx = 0;

    while ((code = getopt.getopt()) != -1)
    {
      switch (code)
      {
        case ':':
          throw new CommandException
            ("Option requires an argument: " + args[getopt.getOptind() - 1]);

        case '?':
          throw new CommandException
            ("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

        case 0x1000:
          prefix = false;
          break;
                 
          // non-option arguments
        case 1:
          {
            String arg = getopt.getOptarg();

            switch (argidx++)
            {
              case 0:
                objectName = createObjectName(arg);
View Full Code Here

Examples of gnu.getopt.Getopt

         new LongOpt("domain", LongOpt.NO_ARGUMENT, null, 'd'),
         new LongOpt("count", LongOpt.NO_ARGUMENT, null, 'c'),
         new LongOpt("list", LongOpt.NO_ARGUMENT, null, 'l'),
      };

      Getopt getopt = new Getopt(null, args, sopts, lopts);
      getopt.setOpterr(false);
     
      int code;
      while ((code = getopt.getopt()) != -1)
      {
         switch (code)
         {
            case ':':
               throw new CommandException
                  ("Option requires an argument: "+ args[getopt.getOptind() - 1]);

            case '?':
               throw new CommandException
                  ("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

            // non-option arguments
            case 1:
               throw new CommandException("Unused argument: " + getopt.getOptarg());

            case 'd':
               mode = DEFAULT_DOMAIN;
               break;
View Full Code Here

Examples of gnu.getopt.Getopt

      LongOpt[] lopts =
      {
         new LongOpt("loader", LongOpt.OPTIONAL_ARGUMENT, null, 'l'),
      };

      Getopt getopt = new Getopt(null, args, sopts, lopts);
      getopt.setOpterr(false);
     
      int code;
      int argidx = 0;
     
      while ((code = getopt.getopt()) != -1)
      {
         switch (code)
         {
            case ':':
               throw new CommandException
                  ("Option requires an argument: "+ args[getopt.getOptind() - 1]);

            case '?':
               throw new CommandException
                  ("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

            // non-option arguments
            case 1:
            {
               String arg = getopt.getOptarg();
              
               switch (argidx++) {
                  case 0:
                     className = arg;
                     log.debug("class name: " + className);
                     break;

                  case 1:
                  {
                     try {
                        objectName = new ObjectName(arg);
                        log.debug("mbean name: " + objectName);
                     }
                     catch (MalformedObjectNameException e) {
                        throw new CommandException("Invalid object name: " + arg);
                     }
                     break;
                  }
                 
                  default:
                     throw new CommandException("Unused argument: " + arg);
               }
               break;
            }

            // Set the loader name
            case 'l':
            {
               String arg = getopt.getOptarg();
              
               try {
                  loaderName = new ObjectName(arg);
                  log.debug("loader name: " + loaderName);
               }
View Full Code Here

Examples of gnu.getopt.Getopt

      LongOpt[] lopts =
         {
            new LongOpt("noprefix", LongOpt.NO_ARGUMENT, null, 0x1000),
         };

      Getopt getopt = new Getopt(null, args, sopts, lopts);
      getopt.setOpterr(false);

      int code;
      int argidx = 0;

      while ((code = getopt.getopt()) != -1)
      {
         switch (code)
         {
            case ':':
               throw new CommandException
                  ("Option requires an argument: " + args[getopt.getOptind() - 1]);

            case '?':
               throw new CommandException
                  ("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

            case 0x1000:
               break;
                 
               // non-option arguments
            case 1:
               {
                  String arg = getopt.getOptarg();

                  switch (argidx++)
                  {
                     case 0:
                        objectName = createObjectName(arg);
View Full Code Here

Examples of gnu.getopt.Getopt

         new LongOpt("password", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
         new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'o'),
         new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'r'),
      };

      Getopt getopt = new Getopt(PROGRAM_NAME, args, sopts, lopts);
      int code;
      String arg;

      String serverURL = null;
      String username = null;
      String password = null;
      ObjectName serverJMXName = new ObjectName("jboss.system:type=Server");
      String hostname=null;
      String port=null;
      boolean verbose = false;

      while ((code = getopt.getopt()) != -1)
      {
         switch (code)
         {
            case ':':
            case '?':
               // for now both of these should exit with error status
               System.exit(1);
               break;

            case 1:
               // this will catch non-option arguments
               // (which we don't currently care about)
               System.err.println(PROGRAM_NAME + ": unused non-option argument: " +
               getopt.getOptarg());
               break;
            case 'h':
               displayUsage();
               System.exit(0);
               break;
            case 'D':
            {
               // set a system property
               arg = getopt.getOptarg();
               String name, value;
               int i = arg.indexOf("=");
               if (i == -1)
               {
                  name = arg;
                  value = "true";
               }
               else
               {
                  name = arg.substring(0, i);
                  value = arg.substring(i + 1, arg.length());
               }
               System.setProperty(name, value);
               break;
            }
            case 's':
               serverURL = getopt.getOptarg();
               break;
            case 'n':
               serverJMXName = new ObjectName(getopt.getOptarg());
               break;
            case 'S':
               // nothing...
               break;
            case 'a':
               String adapterName = getopt.getOptarg();
               System.out.println("adapter name is ignored " + adapterName);
               break;
            case 'u':
               username = getopt.getOptarg();
               break;
            case 'p':
               password = getopt.getOptarg();
               break;
            // host name
            case 'o':
               hostname = getopt.getOptarg();
               break;

            // host port
            case 'r':
               port = getopt.getOptarg();
               break;
            // be noisy
            case 'v':
               verbose = true;
               break;
View Full Code Here

Examples of gnu.getopt.Getopt

            new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'o'),
            new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'r'),
            new LongOpt("password", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
         };

      Getopt getopt = new Getopt(PROGRAM_NAME, args, sopts, lopts);
      int code;

      PROCESS_ARGUMENTS:

        while ((code = getopt.getopt()) != -1)
        {
           switch (code)
           {
              case ':':
              case '?':
                 // for now both of these should exit with error status
                 System.exit(1);
                 break; // for completeness

                 // non-option arguments
              case 1:
                 {
                    // create the command
                    commandName = getopt.getOptarg();
                    log.debug("Command name: " + commandName);

                    // pass the remaining arguments (if any) to the command for processing
                    int i = getopt.getOptind();

                    if (args.length > i)
                    {
                       commandArgs = new String[args.length - i];
                       System.arraycopy(args, i, commandArgs, 0, args.length - i);
                    }
                    else
                    {
                       commandArgs = new String[0];
                    }
                    // Log the command options
                    log.debug("Command arguments: " + Strings.join(commandArgs, ","));

                    // We are done, execute the command
                    break PROCESS_ARGUMENTS;
                 }

                 // show command line help
              case 'h':
                 displayHelp();
                 System.exit(0);
                 break; // for completeness

                 // Show command help
              case 'H':
                 commandName = getopt.getOptarg();
                 commandHelp = true;
                 break PROCESS_ARGUMENTS;

                 // help-commands
              case 0x1000:
                 twiddle.displayCommandList();
                 System.exit(0);
                 break; // for completeness

              case 'c':
                 // Try value as a URL
                 String props = getopt.getOptarg();
                 try
                 {
                    cmdProps = new URL(props);
                 }
                 catch (MalformedURLException e)
                 {
                    log.debug("Failed to use cmd props as url", e);
                    File path = new File(props);
                    if( path.exists() == false )
                    {
                       String msg = "Failed to locate command props: " + props
                          + " as URL or file";
                       throw new IllegalArgumentException(msg);
                    }
                    cmdProps = path.toURL();
                 }
                 break;
                 // set a system property
              case 'D':
                 {
                    String arg = getopt.getOptarg();
                    String name, value;
                    int i = arg.indexOf("=");
                    if (i == -1)
                    {
                       name = arg;
                       value = "true";
                    }
                    else
                    {
                       name = arg.substring(0, i);
                       value = arg.substring(i + 1, arg.length());
                    }
                    System.setProperty(name, value);
                    break;
                 }

                 // host name
              case 'o':
                 twiddle.setHostname(getopt.getOptarg());
                 break;

              // host port
              case 'r':
                 twiddle.setPort(getopt.getOptarg());
                 break;

                 // Set the JNDI server URL
              case 's':
                 twiddle.setServerURL(getopt.getOptarg());
                 break;

                 // adapter JNDI name is not supported anymore
              case 'a':
                 String arg = getopt.getOptarg();
                 log.info("adapter name is ignored " + arg);
                 break;
              case 'u':
                 twiddle.setUsername(getopt.getOptarg());
                 break;
              case 'p':
                 twiddle.setPassword(getopt.getOptarg());
                 break;

              // be noisy
              case 'v':
                 twiddle.setVerbose(true);
View Full Code Here

Examples of gnu.getopt.Getopt

    if (args.length == 0) {
      System.out.println(getLongUsage());
      return -1;
    }
   
    Getopt getopt = new Getopt(getProgramName(), args, ":", longOpts, true);
    //Getopt getopt = new Getopt(getCommandString(), argv, "-:h:vf:b:pc:u:t:y:w:drq", longOpts, true);
    //getopt.setOpterr(false); // We'll do our own error handling
 
    int c;
    while ((c = getopt.getopt()) != -1) {
//      log.trace("longind="+g.getLongind());
      switch (c) {
        case 'h' : // --help
          System.out.println(getLongUsage());
          return -1;
        case 'v' : // --version
          System.out.println(getVersionInfo());
          return -1;
        case 's' : // --strip
          stripWhitespace = true;
          break;
        case 'x' : // --xinclude
          xinclude = true;
          break;
        case 'e' : // --explain
          explain = true;
          break;
        case 'n' : // --noexternal
          System.setProperty("nux.xom.xquery.XQuery.allowExternalFunctions", "false");
          break;
        case 'd' : // --debug
          debug = true;
          break;
        case 'p' : // --nobuilderpool
          noBuilderPool = true;
          break;
        case 'N' : // --xomxpath
          xomXPath = true;
          break;
        case 0
          String arg = getopt.getOptarg();
          char val = (char) (new Integer(sb.toString())).intValue();
          String optionName = longOpts[getopt.getLongind()].getName();
//          log.trace("Got long option with value '" + val + "' with argument " + ((arg != null) ? arg : "null"));
          switch (val) {
            case 'q' : // --query
              arg = arg.trim();
              if (arg.startsWith("{") && arg.endsWith("}")) {
                // query is given inline between curly brackets, ala Saxon command line tool
                queries.add(arg.substring(1, arg.length()-1));
              } else {
                if (arg.equals("nop"))
                  queries.add(null); // disable xquery for benchmarking
                else
                  queries.add(parsePath(arg));
              }
              break;
            case 'u' : // --update
              arg = arg.trim();
              if (arg.startsWith("{") && arg.endsWith("}")) {
                // update query is given inline between curly brackets, ala Saxon command line tool
                update = arg.substring(1, arg.length()-1);
              } else {
                update = parsePath(arg);
              }
              break;
            case 'b' : // --base
              baseURI = parsePath(arg).toURI();
              break;
            case 'P' : { // --var
              int i = arg.indexOf(':');
              if (i < 0) throw new UsageException("Missing name:value pair");
              String name = arg.substring(0, i).trim();
              String value = arg.substring(i+1);
              if (false && value.startsWith("doc(") && value.endsWith(")")) {
                try {
                  value = value.substring("doc(".length()-1);
                  value = value.substring(1, value.length()-1);
                  variables.put(name, new Builder().build(new File(value)));
                } catch (Exception e) {
                  throw new UsageException(e);
                }
              } else {
                variables.put(name, value);
              }
              break;
            }
            case 'o' : // --out
              outputFiles.add(parsePath(arg));
              break;
            case 'S' : // --algo
              arg = arg.trim();
              checkValidity(arg, new String[] {
                ResultSequenceSerializer.W3C_ALGORITHM,
                ResultSequenceSerializer.WRAP_ALGORITHM}, optionName);
              algorithm = arg;
              break;
            case 'E' : // --encoding
              encoding = arg.trim();
              break;
            case 'I' : // --indent
              indent = Math.max(0, parseInt(arg, optionName));
              break;
            case 'r' : // --runs
              runs = parseIntGreaterThanZero(arg, optionName);
              break;
            case 'i' : // --iterations
              iterations = Math.max(0, parseInt(arg, optionName));
              break;
            case 'C' : // --docpoolcapacity
              docPoolCapacity = 1024L * 1024L * parseInt(arg, optionName);
              break;         
            case 'D' : // --docpoolcompression
              docPoolCompression = parseInt(arg, optionName);
              break;         
            case 'V' // --validate
              arg = arg.trim();
              checkValidity(arg, new String[] {
                "wf", "dtd", "schema", "relaxng", "html"}, optionName);
              validate = arg;
              break
            case 'W' // --namespace
              namespace = arg.trim();
              break
            case 'w' : { // --schema
              // if the schema file location is a relative path,
              // xerces interprets it relative to the XML instance document file,
              // not the current working directory.
              // This may be surprising and errorprone, so we convert it to an absolute path
              // Also, there are some obscure work arounds to make this work both on Unix and Windows, in all cases...
              schema = parsePath(arg).getAbsoluteFile();
              break;
            }
            case 'f' : // --filterpath
              try {
                filter = new StreamingPathFilter(arg, null);
              } catch (StreamingPathFilterException e) {
                throw new UsageException(e);
              }
              break
            case 'F' : // --filterquery
              arg = arg.trim();
              if (arg.startsWith("{") && arg.endsWith("}")) {
                // query is given inline between curly brackets, ala Saxon command line tool
                filterQuery = arg.substring(1, arg.length()-1);
              } else {
                try {
                  filterQuery = FileUtil.toString(
                      new FileInputStream(parsePath(arg)), null);
                } catch (IOException e) {
                  throw new UsageException(e);
                }
              }
              break;
////            case 'l' : // --loglevel
////              setLogLevels(toLevel(arg));
////              break;
            default :
              throw new InternalError("Oops. Should never reach here. val='" + val + "'");
          }       
          break;
        case ':' :
          throw new UsageException("Option '" + longOpts[getopt.getLongind()].getName() + "' requires an argument");
          //throw new UsageException("Argument missing for option " + (char) g.getOptopt() + ", errname=" + longopts[g.getLongind()].getName());
        case '?' :
          System.err.println(getLongUsage());
          return -1;
//          throw new UsageException("The option '" + (char) g.getOptopt() + "' is not valid");
        default :
          throw new InternalError("Oops. Should never reach here. getopt() returned '" + (char) c + "'");
      }
    }
 
    if (queries.size() == 0) throw new UsageException("Missing required argument --query");
    inputFiles = parseNonOptionArguments(args, getopt.getOptind(), true, 0, Integer.MAX_VALUE);
    if (inputFiles.length == 0) inputFiles = new String[] { null };
   

    // fill in default, if necessary
    File file = null;
View Full Code Here

Examples of gnu.getopt.Getopt

     */
    public static int[] parseFeatDim(String[] args, String argString)
    {
        Vector features = new Vector();

        Getopt opt = new Getopt("MEAPUtil", args, argString);
        opt.setOpterr(false);
       
        int c = -1;
        while ((c = opt.getopt()) != -1)
        {
            if(c == 'i')
            {
                String[] dims = opt.getOptarg().split(",");
                for(int x = 0; x < dims.length; x++)
                {
                    String[] range = dims[x].split("[:-]",2);
                    int start = Integer.parseInt(range[0]);
                    features.add(new Integer(start));
View Full Code Here

Examples of gnu.getopt.Getopt

     */
    public static ChunkDist parseChunkDist(String[] args, String argString, int[] featdim)
    {
        ChunkDist dist = null;

        Getopt opt = new Getopt("MEAPUtil", args, argString);
        opt.setOpterr(false);
       
        int c = -1;
        while ((c = opt.getopt()) != -1)
        {
            if(c == 'd')
            {
                String className = opt.getOptarg();

                // Try to load the class named className that extends
                // ChunkDist.  (This is ugly as hell)
                Class cl = null;
                try
View Full Code Here

Examples of gnu.getopt.Getopt

   */
  public static int[] parseFeatDim(String[] args, String argString)
  {
    Vector features = new Vector();

    Getopt opt = new Getopt("MEAPUtil", args, argString);
    opt.setOpterr(false);

    int c = -1;
    while ((c = opt.getopt()) != -1)
    {
      if (c == 'i')
      {
        String[] dims = opt.getOptarg().split(",");
        for (int x = 0; x < dims.length; x++)
        {
          String[] range = dims[x].split("[:-]", 2);
          int start = Integer.parseInt(range[0]);
          features.add(new Integer(start));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.