Examples of Getopt


Examples of com.darwinsys.lang.GetOpt

   */
  public static void main(final String[] args) {
    String config = "default";
    String outputModeName = "t";
    String outputFile = null;
    final GetOpt go = new GetOpt("dvf:c:m:o:");
    char c;
    while ((c = go.getopt(args)) != GetOpt.DONE) {
      switch(c) {
      case 'h':
        doHelp(0);
        break;
      case 'd':
        SQLRunner.setVerbosity(Verbosity.DEBUG);
        break;
      case 'v':
        SQLRunner.setVerbosity(Verbosity.VERBOSE);
        break;
      case 'f':
        ConnectionUtil.setConfigFileName(go.optarg());
        break;
      case 'c':
        config = go.optarg();
        break;
      case 'm':
        outputModeName = go.optarg();
        break;
      case 'o':
        outputFile = go.optarg();
        break;
      default:
        System.err.println("Unknown option character " + c);
        doHelp(1);
      }
    }

    try {

      Configuration conf = ConnectionUtil.getConfiguration(config);
      if (!conf.hasPassword()) {
        System.err.printf("Enter password for connection %s: ", config);
        System.err.flush();
        Scanner sc = new Scanner(System.in);      // Requires J2SE 1.5
              String newPass = sc.next();
        conf.setPassword(newPass);
      }
      Connection conn = ConnectionUtil.getConnection(conf);


      SQLRunner prog = new SQLRunner(conn, outputFile, outputModeName);

      if (go.getOptInd() == args.length) {
        runScript(prog, new BufferedReader(
          new InputStreamReader(System.in)), "(standard input)");
      } else for (int i = go.getOptInd()-1; i < args.length; i++) {
        runScript(prog, args[i]);
      }
      prog.close();
    } catch (SQLException ex) {
      throw new DataBaseException(ex.toString());
View Full Code Here

Examples of com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOpt

    public static void main(String[] args) {
  try {
      boolean inputIsURL = false;
      boolean useStdIn = false;
      boolean classNameSet = false;
      final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
      if (args.length < 1) printUsage();

      final XSLTC xsltc = new XSLTC();
      xsltc.init();

      int c;
      while ((c = getopt.getNextOption()) != -1) {
    switch(c) {
    case 'i':
        useStdIn = true;
        break;
    case 'o':
        xsltc.setClassName(getopt.getOptionArg());
        classNameSet = true;
        break;
    case 'd':
        xsltc.setDestDirectory(getopt.getOptionArg());
        break;
    case 'p':
        xsltc.setPackageName(getopt.getOptionArg());
        break;
    case 'j'
        xsltc.setJarFileName(getopt.getOptionArg());
        break;
    case 'x':
        xsltc.setDebug(true);
        break;
    case 'u':
        inputIsURL = true;
        break;
    case 's':
        _allowExit = false;
        break;                    
    case 'n':
        xsltc.setTemplateInlining(true)// used to be 'false'
        break;
    case 'v':
        // fall through to case h
    case 'h':
    default:
        printUsage();
        break;
    }
      }

      boolean compileOK;

      if (useStdIn) {
    if (!classNameSet) {
        System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR));
                    if (_allowExit) System.exit(-1);
    }
    compileOK = xsltc.compile(System.in, xsltc.getClassName());
      }
      else {
    // Generate a vector containg URLs for all stylesheets specified
    final String[] stylesheetNames = getopt.getCmdArgs();
    final Vector   stylesheetVector = new Vector();
    for (int i = 0; i < stylesheetNames.length; i++) {
        final String name = stylesheetNames[i];
        URL url;
        if (inputIsURL)
View Full Code Here

Examples of gnu.getopt.Getopt

  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

Examples of gnu.getopt.Getopt

            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

Examples of gnu.getopt.Getopt

      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

Examples of gnu.getopt.Getopt

        {
            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

Examples of gnu.getopt.Getopt

      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

Examples of gnu.getopt.Getopt

      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

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

    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
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.