Package gnu.getopt

Examples of gnu.getopt.Getopt$OptI18n


  new LongOpt("basic-regexp",        LongOpt.NO_ARGUMENT, null, 'G'),
  new LongOpt("files-without-match", LongOpt.NO_ARGUMENT, null, 'L'),
  new LongOpt("version",             LongOpt.NO_ARGUMENT, null, 'V')
    };

    Getopt g = new Getopt(PROGNAME, argv, "bchilnqsvxyEFGLV", longOptions);
    int c;
    String arg;
    while ((c = g.getopt()) != -1) {
      switch (c) {
      case 'b':
  options[BYTE_OFFSET] = true;
  break;
      case 'c':
  options[COUNT] = true;
  break;
      case 'h':
  options[NO_FILENAME] = true;
  break;
      case 'i':
      case 'y':
  cflags |= RE.REG_ICASE;
  break;
      case 'l':
  options[FILES_WITH_MATCHES] = true;
  break;
      case 'n':
  options[LINE_NUMBER] = true;
  break;
      case 'q':
  options[QUIET] = true;
  break;
      case 's':
  options[SILENT] = true;
  break;
      case 'v':
  options[REVERT_MATCH] = true;
  break;
      case 'x':
  options[LINE_REGEXP] = true;
  break;
      case 'E'// TODO: check compatibility with grep
  syntax = RESyntax.RE_SYNTAX_EGREP;
  break;
      case 'F'// TODO: fixed strings
  break;
      case 'G':
  syntax = RESyntax.RE_SYNTAX_GREP;
  break;
      case 'L':
  options[FILES_WITHOUT_MATCH] = true;
  break;
      case 'V':
  System.err.println(PROGNAME+' '+PROGVERSION);
  return 0;
      case '!': // help
  BufferedReader br = new BufferedReader(new InputStreamReader((Grep.class).getResourceAsStream("GrepUsage.txt")));
  String line;
  try {
    while ((line = br.readLine()) != null)
      out.println(line);
  } catch (IOException ie) { }
  return 0;
      }
    }       
   
    InputStream is = null;
    RE pattern = null;
    int optind = g.getOptind();
    if (optind >= argv.length) {
      System.err.println("Usage: java " + PROGNAME + " [OPTION]... PATTERN [FILE]...");
      System.err.println("Try `java " + PROGNAME + " --help' for more information.");
      return 2;
    }
    try {
      pattern = new RE(argv[g.getOptind()],cflags,syntax);
    } catch (REException e) {
      System.err.println("Error in expression: "+e);
      return 2;
    }
    int retval = 1;
    if (argv.length >= g.getOptind()+2) {
      for (int i = g.getOptind() + 1; i < argv.length; i++) {
  if (argv[i].equals("-")) {
    if (processStream(pattern,System.in,options,(argv.length == g.getOptind()+2) || options[NO_FILENAME] ? null : "(standard input)",out)) {
      retval = 0;
    }
  } else {
    try {
      is = new FileInputStream(argv[i]);
      if (processStream(pattern,is,options,(argv.length == g.getOptind()+2) || options[NO_FILENAME] ? null : argv[i],out))
        retval = 0;
    } catch (FileNotFoundException e) {
      if (!options[SILENT])
        System.err.println(PROGNAME+": "+e);
    }
View Full Code Here


            new LongOpt("mcast_port", LongOpt.REQUIRED_ARGUMENT, null, 'm'),
            new LongOpt("hostname", LongOpt.REQUIRED_ARGUMENT, null, 'H'),
            new LongOpt("nodename", LongOpt.REQUIRED_ARGUMENT, null, 'N'),
      };

      Getopt getopt = new Getopt(programName, args, sopts, lopts);
      int code;
      String arg;
      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

            case 1 :
               // this will catch non-option arguments
               // (which we don't currently care about)
               System.err.println(programName + ": unused non-option argument: " + getopt.getOptarg());
               break; // for completeness

            case 'h' :
               // show command line help
               System.out.println("usage: " + programName + " [options]");
               System.out.println();
               System.out.println("options:");
               System.out.println("    -h, --help                    Show this help message");
               System.out.println("    -V, --version                 Show version information");
               System.out.println("    --                            Stop processing options");
               System.out.println("    -D<name>[=<value>]            Set a system property");
               System.out
                     .println("    -d, --bootdir=<dir>           Set the boot patch directory; Must be absolute or url");
               System.out.println("    -p, --patchdir=<dir>          Set the patch directory; Must be absolute or url");
               System.out.println("    -n, --netboot=<url>           Boot from net with the given url as base");
               System.out.println("    -c, --configuration=<name>    Set the server configuration name");
               System.out.println("    -B, --bootlib=<filename>      Add an extra library to the front bootclasspath");
               System.out.println("    -L, --library=<filename>      Add an extra library to the loaders classpath");
               System.out.println("    -C, --classpath=<url>         Add an extra url to the loaders classpath");
               System.out.println("    -P, --properties=<url>        Load system properties from the given url");
               System.out.println("    -b, --host=<host or ip>       Bind address for all JBoss services");
               System.out.println("    -g, --partition=<name>        HA Partition name (default=DefaultDomain)");
               System.out.println("    -m, --mcast_port=<ip>         UDP multicast port; only used by JGroups");
               System.out.println("    -u, --udp=<ip>                UDP multicast address");
               System.out.println("    -H, --hostname=<name>         Set the host name");
               System.out.println("    -N, --nodename=<name>         Set the node name to use");
               System.out.println();
               System.exit(0);
               break; // for completeness

            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);
               // Ensure setting the old bind.address property also sets the new
               // jgroups.bind_addr property, otherwise jgroups may ignore it
               if ("bind.address".equals(name))
               {
                  System.setProperty("jgroups.bind_addr", value);
               }
               break;
            }

            case 'd' :
               // set the boot patch URL
               bootURL = makeURL(getopt.getOptarg());
               break;

            case 'p' : {
               // set the patch URL
               URL patchURL = makeURL(getopt.getOptarg());
               //TODO
               //               props.put(ServerConfig.PATCH_URL, patchURL.toString());

               break;
            }

            case 'n' :
               // set the net boot url
               arg = getopt.getOptarg();

               // make sure there is a trailing '/'
               if (!arg.endsWith("/"))
                  arg += "/";

               props.put(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME_URL, new URL(arg).toString());
               break;

            case 'c' :
               // set the server name
               arg = getopt.getOptarg();
               props.put(JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_NAME, arg);
               break;

            case 'V' : {
               // Package information for org.jboss
               Package jbossPackage = Package.getPackage("org.jboss");

               // show version information
               System.out.println("JBoss " + jbossPackage.getImplementationVersion());
               System.out.println();
               System.out.println("Distributable under LGPL license.");
               System.out.println("See terms of license at gnu.org.");
               System.out.println();
               System.exit(0);
               break; // for completness
            }

            case 'j' :
               // Show an error and exit
               System.err.println(programName + ": option '-j, --jaxp' no longer supported");
               System.exit(1);
               break; // for completness

            case 'B' :
               arg = getopt.getOptarg();
               bootLibraries.add(new File(arg).toURI().toURL());
               break;

            case 'L' :
               arg = getopt.getOptarg();
               extraLibraries.add(new File(arg).toURI().toURL());
               break;

            case 'C' : {
               URL url = makeURL(getopt.getOptarg());
               extraClasspath.add(url);
               break;
            }

            case 'P' : {
               // Set system properties from url/file
               URL url = makeURL(getopt.getOptarg());
               Properties props = System.getProperties();
               props.load(url.openConnection().getInputStream());
               break;
            }
            case 'b' :
               arg = getopt.getOptarg();
               final String bindAddressPropName = JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS;
               props.put(bindAddressPropName, arg);
               System.setProperty(bindAddressPropName, arg);
               // used by JGroups; only set if not set via -D so users
               // can use a different interface for cluster communication
               // There are 2 versions of this property, deprecated bind.address
               // and the new version, jgroups.bind_addr
               String bindAddress = System.getProperty("bind.address");
               if (bindAddress == null)
               {
                  System.setProperty("bind.address", arg);
               }
               bindAddress = System.getProperty("jgroups.bind_addr");
               if (bindAddress == null)
               {
                  System.setProperty("jgroups.bind_addr", arg);
               }

               // Set the java.rmi.server.hostname if not set
               String rmiHost = System.getProperty("java.rmi.server.hostname");
               if (rmiHost == null)
               {
                  System.setProperty("java.rmi.server.hostname", arg);
               }
               break;

            case 'g' :
               arg = getopt.getOptarg();
               final String partitionNamePropName = JBossASServerConfig.PROP_KEY_JBOSSAS_PARTITION_NAME;
               props.put(partitionNamePropName, arg);
               System.setProperty(partitionNamePropName, arg);
               break;

            case 'u' :
               arg = getopt.getOptarg();
               final String udpGroupPropName = JBossASServerConfig.PROP_KEY_JBOSSAS_PARTITION_UDP_GROUP;
               props.put(udpGroupPropName, arg);
               System.setProperty(udpGroupPropName, arg);
               // the new jgroups property name
               System.setProperty("jgroups.udp.mcast_addr", arg);
               break;

            case 'm' :
               arg = getopt.getOptarg();
               final String udpPortPropName = JBossASServerConfig.PROP_KEY_JBOSSAS_PARTITION_UDP_PORT;
               props.put(udpPortPropName, arg);
               System.setProperty(udpPortPropName, arg);
               break;

            case 'H' : {
               arg = getopt.getOptarg();
               System.setProperty("jboss.qualified.host.name", arg.trim().toLowerCase());
               break;
            }

            case 'N' : {
               arg = getopt.getOptarg();
               System.setProperty("jboss.node.name", arg.trim());
               break;
            }

            default :
View Full Code Here

      LongOpt[] lopts =
      {
         // new LongOpt("count", LongOpt.NO_ARGUMENT, null, 'c'),
      };

      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++) {
                  default:
                     names.add(createObjectName(arg));
                     break;
View Full Code Here

        {
            new LongOpt( "count", LongOpt.NO_ARGUMENT, null, 'c' ),
            new LongOpt( "filter", LongOpt.REQUIRED_ARGUMENT, null, 'f' ),
        };

    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:
              query = arg;
              log.debug( "query: " + query );
              break;

            default:
              throw new CommandException( "Unused argument: " + arg );
          }
          break;
        }

        // Show count
        case 'c':
          displayCount = true;
          break;

        case 'f':
          filter = getopt.getOptarg();
          log.debug( "filter: " + filter );
          break;
      }
    }
  }
View Full Code Here

      LongOpt[] lopts =
         {
            new LongOpt("query-type", LongOpt.OPTIONAL_ARGUMENT, null, 'q'),
         };

      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:
                        query = arg;
                        log.debug("query: " + query);
                        break;

                     case 1:
                        opName = arg;
                        log.debug("operation name: " + opName);
                        break;

                     default:
                        opArgs.add(arg);
                        break;
                  }
                  break;
               }

               // Set the query type
            case 'q':
               {
                  String arg = getopt.getOptarg();

                  //
                  // jason: need a uniqueness mapper, like getopt uses for options...
                  //
View Full Code Here

      String sopts = "-:";
      LongOpt[] lopts =
         {
         };

      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:
                        objectName = createObjectName(arg);
View Full Code Here

      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

    LongOpt[] lopts =
        {
            new LongOpt( "count", LongOpt.NO_ARGUMENT, null, 'c' ),
        };

    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++ ) {
            default:
              throw new CommandException( "Unused argument: " + arg );
          }
View Full Code Here

    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

         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

TOP

Related Classes of gnu.getopt.Getopt$OptI18n

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.