当前位置: 首页>>代码示例>>Java>>正文


Java Getopt.getOptind方法代码示例

本文整理汇总了Java中gnu.getopt.Getopt.getOptind方法的典型用法代码示例。如果您正苦于以下问题:Java Getopt.getOptind方法的具体用法?Java Getopt.getOptind怎么用?Java Getopt.getOptind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.getopt.Getopt的用法示例。


在下文中一共展示了Getopt.getOptind方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import gnu.getopt.Getopt; //导入方法依赖的package包/类
/**
 * Parse the command line arguments and notify option listeners.
 */    
public void parse() throws OptionsException {
  Getopt g = new Getopt(application, argv, sargs.toString(), largs.toArray(new LongOpt[] {}));
  g.setOpterr(false); // We'll do our own error handling
  
  int c;
  while ((c = g.getopt()) != -1) {
    switch (c) {
    case '?':
      // Get invalid option
      int ix = g.getOptind();
      String option = argv[(ix == 0 ? 0 : ix-1)];
      throw new OptionsException(option, g.getOptarg());
    default:
      ListenerIF listener = listeners.get(new Integer(c));
      if (listener != null)
        listener.processOption((char)c, g.getOptarg());
      else
        System.err.println ("Warning: option '" + (char)c + "' ignored");
      break;
    }
  }
  
  // Get non-option arguments
  for (int i = g.getOptind(); i < argv.length ; i++) {
    arguments.add(argv[i]);
  }
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:31,代码来源:CmdlineOptions.java

示例2: main

import gnu.getopt.Getopt; //导入方法依赖的package包/类
public static void
main(String[] argv)
{
 int c;
 String arg;
 LongOpt[] longopts = new LongOpt[3];
 // 
 StringBuffer sb = new StringBuffer();
 longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
 longopts[1] = new LongOpt("outputdir", LongOpt.REQUIRED_ARGUMENT, sb, 'o'); 
 longopts[2] = new LongOpt("maximum", LongOpt.OPTIONAL_ARGUMENT, null, 2);
 // 
 Getopt g = new Getopt("testprog", argv, "-:bc::d:hW;", longopts);
 g.setOpterr(false); // We'll do our own error handling
 //
 while ((c = g.getopt()) != -1)
   switch (c)
     {
        case 0:
          arg = g.getOptarg();
          System.out.println("Got long option with value '" +
                             (char)(new Integer(sb.toString())).intValue()
                             + "' with argument " +
                             ((arg != null) ? arg : "null"));
          break;
          //
        case 1:
          System.out.println("I see you have return in order set and that " +
                             "a non-option argv element was just found " +
                             "with the value '" + g.getOptarg() + "'");
          break;
          //
        case 2:
          arg = g.getOptarg();
          System.out.println("I know this, but pretend I didn't");
          System.out.println("We picked option " +
                             longopts[g.getLongind()].getName() +
                           " with value " + 
                           ((arg != null) ? arg : "null"));
          break;
          //
        case 'b':
          System.out.println("You picked plain old option " + (char)c);
          break;
          //
        case 'c':
        case 'd':
          arg = g.getOptarg();
          System.out.println("You picked option '" + (char)c + 
                             "' with argument " +
                             ((arg != null) ? arg : "null"));
          break;
          //
        case 'h':
          System.out.println("I see you asked for help");
          break;
          //
        case 'W':
          System.out.println("Hmmm. You tried a -W with an incorrect long " +
                             "option name");
          break;
          //
        case ':':
          System.out.println("Doh! You need an argument for option " +
                             (char)g.getOptopt());
          break;
          //
        case '?':
          System.out.println("The option '" + (char)g.getOptopt() + 
                           "' is not valid");
          break;
          //
        default:
          System.out.println("getopt() returned " + c);
          break;
     }
 //
 for (int i = g.getOptind(); i < argv.length ; i++)
   System.out.println("Non option argv element: " + argv[i] + "\n");
}
 
开发者ID:mrmaxent,项目名称:Maxent,代码行数:81,代码来源:GetoptDemo.java

示例3: parseArguments

import gnu.getopt.Getopt; //导入方法依赖的package包/类
private static BenchmarkTest parseArguments(String[] args) throws Exception
{
   String shortOpts = "t:r:s:i:a:vh";
   LongOpt[] longOpts =
   {new LongOpt("deployment", LongOpt.REQUIRED_ARGUMENT, null, 'd'),
         new LongOpt("threads", LongOpt.REQUIRED_ARGUMENT, null, 't'),
         new LongOpt("runs", LongOpt.REQUIRED_ARGUMENT, null, 'r'),
         new LongOpt("sleep", LongOpt.REQUIRED_ARGUMENT, null, 's'),
         new LongOpt("iterations", LongOpt.REQUIRED_ARGUMENT, null, 'i'),
         new LongOpt("address", LongOpt.REQUIRED_ARGUMENT, null, 'a'),
         new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v'), new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h')};

   Getopt getopt = new Getopt("Benchmark-runner", args, shortOpts, longOpts);
   int c;
   while ((c = getopt.getopt()) != -1)
   {
      switch (c)
      {
         case 't' :
            threadCount = Integer.parseInt(getopt.getOptarg());
            break;
         case 'r' :
            runs = Integer.parseInt(getopt.getOptarg());
            break;
         case 's' :
            sleep = Long.parseLong(getopt.getOptarg());
            break;
         case 'i' :
            iterations = Integer.parseInt(getopt.getOptarg());
            break;
         case 'a' :
            address = getopt.getOptarg();
            break;
         case 'v' :
            verbose = true;
            break;
         case 'h' :
            printHelp();
            System.exit(0);
         case '?' :
            System.exit(1);
      }
   }

   int classPos = getopt.getOptind();
   if (classPos >= args.length)
   {
      System.err.println("Error: test-class was not specified!");
      printHelp();
      System.exit(1);
   }

   try
   {
      Class<?> clazz = Class.forName(args[classPos]);
      System.out.println(BenchmarkTest.class.isAssignableFrom(clazz));
      System.out.println(clazz.isAssignableFrom(BenchmarkTest.class));

      return (BenchmarkTest) clazz.newInstance();
   }
   catch (Exception e)
   {
      System.out.println("Cannot instanciate " + args[classPos]);
      throw e;
   }
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:67,代码来源:Runner.java

示例4: main

import gnu.getopt.Getopt; //导入方法依赖的package包/类
/**
 * SSLEepGet https://foo/bar
 *   or to save cert chain:
 * SSLEepGet -s https://foo/bar
 */ 
public static void main(String args[]) {
    boolean saveCerts = false;
    boolean error = false;
    Getopt g = new Getopt("ssleepget", args, "s");
    try {
        int c;
        while ((c = g.getopt()) != -1) {
          switch (c) {
            case 's':
                saveCerts = true;
                break;

            case '?':
            case ':':
            default:
                error = true;
                break;
          }  // switch
        } // while
    } catch (Exception e) {
        e.printStackTrace();
        error = true;
    }

    if (error || args.length - g.getOptind() != 1) {
        usage();
        System.exit(1);
    }
    String url = args[g.getOptind()];

    String saveAs = suggestName(url);
    OutputStream out;
    try {
        // resume from a previous eepget won't work right doing it this way
        out = new FileOutputStream(saveAs);
    } catch (IOException ioe) {
        System.err.println("Failed to create output file " + saveAs);
        return;
    }

    SSLEepGet get = new SSLEepGet(I2PAppContext.getGlobalContext(), out, url);
    if (saveCerts)
        get._saveCerts = true;
    get._commandLine = true;
    get.addStatusListener(get.new CLIStatusListener(1024, 40));
    if(!get.fetch(45*1000, -1, 60*1000))
        System.exit(1);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:54,代码来源:SSLEepGet.java

示例5: main

import gnu.getopt.Getopt; //导入方法依赖的package包/类
/**
 *  Usage: Router [rebuild]
 *  No other options allowed, for now
 *
 *  @param args null ok
 *  @throws IllegalArgumentException
 */
public static void main(String args[]) {
    boolean rebuild = false;
    if (args != null) {
        boolean error = false;
        Getopt g = new Getopt("router", args, "");
        int c;
        while ((c = g.getopt()) != -1) {
            switch (c) {
                default:
                    error = true;
            }
        }
        int remaining = args.length - g.getOptind();
        if (remaining > 1) {
            error = true;
        } else if (remaining == 1) {
            rebuild = args[g.getOptind()].equals("rebuild");;
            if (!rebuild)
                error = true;
        }
        if (error)
            throw new IllegalArgumentException();
    }

    System.out.println("Starting I2P " + RouterVersion.FULL_VERSION);
    //verifyWrapperConfig();
    Router r = new Router();
    if (rebuild) {
        r.rebuildNewIdentity();
    } else {
        // This is here so that we can get the directory location from the context
        // for the zip file and the base location to unzip to.
        // If it does an update, it never returns.
        // I guess it's better to have the other-router check above this, we don't want to
        // overwrite an existing running router's jar files. Other than ours.
        r.installUpdates();
        // *********  Start no threads before here ********* //
        r.runRouter();
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:48,代码来源:Router.java

示例6: main

import gnu.getopt.Getopt; //导入方法依赖的package包/类
/**
 *  Usage: Router [rebuild]
 *  No other options allowed, for now
 *  Instantiates Router(), and either installs updates and exits,
 *  or calls runRouter().
 *
 *  Not recommended for embedded use.
 *  Applications bundling I2P should instantiate a Router and call runRouter().
 *
 *  @param args null ok
 *  @throws IllegalArgumentException
 */
public static void main(String args[]) {
    boolean rebuild = false;
    if (args != null) {
        boolean error = false;
        Getopt g = new Getopt("router", args, "");
        int c;
        while ((c = g.getopt()) != -1) {
            switch (c) {
                default:
                    error = true;
            }
        }
        int remaining = args.length - g.getOptind();
        if (remaining > 1) {
            error = true;
        } else if (remaining == 1) {
            rebuild = args[g.getOptind()].equals("rebuild");;
            if (!rebuild)
                error = true;
        }
        if (error)
            throw new IllegalArgumentException();
    }

    System.out.println("Starting I2P " + RouterVersion.FULL_VERSION);
    //verifyWrapperConfig();
    Router r;
    try {
        r = new Router();
    } catch (IllegalStateException ise) {
        System.exit(-1);
        return;
    }
    if (rebuild) {
        r.rebuildNewIdentity();
    } else {
        // This is here so that we can get the directory location from the context
        // for the zip file and the base location to unzip to.
        // If it does an update, it never returns.
        // I guess it's better to have the other-router check above this, we don't want to
        // overwrite an existing running router's jar files. Other than ours.
        InstallUpdate.installUpdates(r);
        // *********  Start no threads before here ********* //
        r.runRouter();
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:59,代码来源:Router.java

示例7: main

import gnu.getopt.Getopt; //导入方法依赖的package包/类
/**
 * SSLEepGet https://foo/bar
 *   or to save cert chain:
 * SSLEepGet -s https://foo/bar
 */ 
public static void main(String args[]) {
    int saveCerts = 0;
    boolean noVerify = false;
    boolean error = false;
    Getopt g = new Getopt("ssleepget", args, "sz");
    try {
        int c;
        while ((c = g.getopt()) != -1) {
          switch (c) {
            case 's':
                saveCerts++;
                break;

            case 'z':
                noVerify = true;
                break;

            case '?':
            case ':':
            default:
                error = true;
                break;
          }  // switch
        } // while
    } catch (Exception e) {
        e.printStackTrace();
        error = true;
    }

    if (error || args.length - g.getOptind() != 1) {
        usage();
        System.exit(1);
    }
    String url = args[g.getOptind()];

    String saveAs = suggestName(url);
    OutputStream out;
    try {
        // resume from a previous eepget won't work right doing it this way
        out = new FileOutputStream(saveAs);
    } catch (IOException ioe) {
        System.err.println("Failed to create output file " + saveAs);
        return;
    }

    SSLEepGet get = new SSLEepGet(I2PAppContext.getGlobalContext(), out, url);
    if (saveCerts > 0)
        get._saveCerts = saveCerts;
    if (noVerify)
        get._bypassVerification = true;
    get._commandLine = true;
    get.addStatusListener(get.new CLIStatusListener(1024, 40));
    if(!get.fetch(45*1000, -1, 60*1000))
        System.exit(1);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:61,代码来源:SSLEepGet.java

示例8: readParameters

import gnu.getopt.Getopt; //导入方法依赖的package包/类
public Properties readParameters( String[] args ) throws java.net.MalformedURLException {
Properties params = new Properties();

params.setProperty( "host", HOST );

// Read parameters
LongOpt[] longopts = new LongOpt[8];
// General parameters
longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("debug", LongOpt.OPTIONAL_ARGUMENT, null, 'd');
longopts[2] = new LongOpt("D", LongOpt.REQUIRED_ARGUMENT, null, 'D');
// Service parameters
longopts[3] = new LongOpt("server", LongOpt.REQUIRED_ARGUMENT, null, 'S');
longopts[4] = new LongOpt("rest", LongOpt.NO_ARGUMENT, null, 'r');

Getopt g = new Getopt("", args, "rhD:d::S:", longopts);
int c;
String arg;

while ((c = g.getopt()) != -1) {
    switch (c) {
    case 'h' :
	usage();
	System.exit(0);
    case 'd' :
	/* Debug level  */
	arg = g.getOptarg();
	if ( arg != null ) debug = Integer.parseInt(arg.trim());
	else debug = 4;
	break;
    case 'r' :
	/* Use direct HTTP interface (REST)  */
	rest = true;
	break;
    case 'S' :
	/* HTTP Server + port */
	arg = g.getOptarg();
	SERVUrl = arg;
	break;
    case 'D' :
	/* Parameter definition */
	arg = g.getOptarg();
	int index = arg.indexOf('=');
	if ( index != -1 ) {
	    params.setProperty( arg.substring( 0, index), 
				 arg.substring(index+1));
	} else {
	    System.err.println("Bad parameter syntax: "+g);
	    usage();
	    System.exit(0);
	}
	break;
    }
}

if (debug > 0) {
    params.setProperty("debug", Integer.toString( debug ) );
} else if ( params.getProperty("debug") != null ) {
    debug = Integer.parseInt((String)params.getProperty("debug"));
}

// Store the remaining arguments in param
int i = g.getOptind();
if ( args.length < i + 1 ){
    usage();
    System.exit(-1);
} else {
    params.setProperty("command", args[i++]);
    for ( int k = 1; i < args.length; i++,k++ ){
	params.setProperty("arg"+k, args[i]);
    }
}
return params;
   }
 
开发者ID:dozed,项目名称:align-api-project,代码行数:75,代码来源:AlignmentClient.java


注:本文中的gnu.getopt.Getopt.getOptind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。