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


Java LongOpt类代码示例

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


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

示例1: getShortOpts

import gnu.getopt.LongOpt; //导入依赖的package包/类
private static String getShortOpts(Option[] opts)
                     throws Exception {
     StringBuilder   buf = new StringBuilder();
     for (int i = 0; i < opts.length; i++) {
         char    c = (char)opts[i].getVal();
if (!Character.isLetterOrDigit(c))
	continue;
         for (int j = 0; j < buf.length(); j++)
             if (buf.charAt(j) == c)
                 throw new Exception(
                         "Duplicate short option " + c
                             );
         buf.append(c);
         switch (opts[i].getHasArg()) {
             case LongOpt.NO_ARGUMENT:
                 break;
             case LongOpt.OPTIONAL_ARGUMENT:
                 buf.append("::");
                 break;
             case LongOpt.REQUIRED_ARGUMENT:
                 buf.append(":");
                 break;
         }
     }
     return buf.toString();
 }
 
开发者ID:nativelibs4java,项目名称:JNAerator,代码行数:27,代码来源:Main.java

示例2: getShortOptions

import gnu.getopt.LongOpt; //导入依赖的package包/类
/**
 * For no adequately explored reason we need to build an array of
 * short options as well as the long ones
 */
private String getShortOptions(LongOpt[] options)
{
    final StringBuffer shortOpts = new StringBuffer();

    for (LongOpt l : options)
    {
        shortOpts.append((char) l.getVal());

        if (l.getHasArg() == LongOpt.REQUIRED_ARGUMENT)
        {
            shortOpts.append(":");
        }
        else if (l.getHasArg() == LongOpt.OPTIONAL_ARGUMENT)
        {
            shortOpts.append("::");
        }
    }

    return shortOpts.toString();
}
 
开发者ID:madebyjeffrey,项目名称:TerraJ,代码行数:25,代码来源:PlanetCLI.java

示例3: usage

import gnu.getopt.LongOpt; //导入依赖的package包/类
private static void usage(String command, Option[] options) {
     StringBuilder   text = new StringBuilder("Usage: ");
     text.append(command).append('\n');
     for (int i = 0; i < options.length; i++) {
         StringBuilder   line = new StringBuilder();
         Option          opt = options[i];
         line.append("    --").append(opt.getName());
         switch (opt.getHasArg()) {
             case LongOpt.NO_ARGUMENT:
                 break;
             case LongOpt.OPTIONAL_ARGUMENT:
                 line.append("[=").append(opt.eg).append(']');
                 break;
             case LongOpt.REQUIRED_ARGUMENT:
                 line.append('=').append(opt.eg);
                 break;
         }
if (Character.isLetterOrDigit(opt.getVal()))
	line.append(" (-").append((char)opt.getVal()).append(")");
         if (line.length() < 30) {
             while (line.length() < 30)
                 line.append(' ');
         }
         else {
             line.append('\n');
             for (int j = 0; j < 30; j++)
                 line.append(' ');
         }
         /* This should use wrap. */
         line.append(opt.help);
         line.append('\n');
         text.append(line);
     }

     System.out.println(text);
 }
 
开发者ID:nativelibs4java,项目名称:JNAerator,代码行数:37,代码来源:Main.java

示例4: addLong

import gnu.getopt.LongOpt; //导入依赖的package包/类
/**
 * Add a long argumentless option with the specified listener.
 */    
public void addLong(ListenerIF listener, String name, char c) {
  // No argument
  largs.add(new LongOpt(name, LongOpt.NO_ARGUMENT, null, c));
  // Register listener
  listeners.put(new Integer(c), listener);    
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:10,代码来源:CmdlineOptions.java

示例5: parse

import gnu.getopt.LongOpt; //导入依赖的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

示例6: createLongOpts

import gnu.getopt.LongOpt; //导入依赖的package包/类
public static LongOpt[] createLongOpts(Option[] opts) {
	LongOpt[] out = new LongOpt[opts.length];
	for (int i = 0; i < opts.length; ++i) {
		out[i] = new LongOpt(
				opts[i].longStr,
				(opts[i].arg == Arg.NONE ? LongOpt.NO_ARGUMENT
						: opts[i].arg == Arg.OPTIONAL ? LongOpt.OPTIONAL_ARGUMENT
								: LongOpt.REQUIRED_ARGUMENT), null,
				opts[i].optChar);
	}
	return out;
}
 
开发者ID:wolpertinger-reasoner,项目名称:Wolpertinger,代码行数:13,代码来源:WolpertingerCli.java

示例7: AbstractArgsParser

import gnu.getopt.LongOpt; //导入依赖的package包/类
/**
 * Parameterized constructor.
 *
 * @param programName the application name
 * @param shortOptions the GetOpts short options spec
 * @param longOptions the GetOpts long options
 */
public AbstractArgsParser(String programName, String shortOptions, LongOpt[] longOptions) {
    super();

    Check.notEmpty(programName, programName);
    Check.notEmpty(shortOptions, shortOptions);
    Preconditions.checkArgument(null != longOptions && longOptions.length > 0, "longOptions");

    this.programName = programName;
    this.shortOptions = shortOptions;
    this.longOptions = longOptions;
}
 
开发者ID:imagopole,项目名称:omero-csv-tools,代码行数:19,代码来源:AbstractArgsParser.java

示例8: processOption

import gnu.getopt.LongOpt; //导入依赖的package包/类
private static String[] processOption(String[] args, Properties props) {
	LongOpt[] options = new LongOpt[] {
			new LongOpt("output", LongOpt.REQUIRED_ARGUMENT,null, 'o')
	};
	
	// Build auxilary structures
	HashMap<Integer, LongOpt> shortOptionMap = new HashMap<Integer, LongOpt>();
	StringBuffer decl = new StringBuffer();
	for(LongOpt o: options) {
		shortOptionMap.put(o.getVal(),o);
		decl.append((char)o.getVal());
		if(o.getHasArg() == LongOpt.OPTIONAL_ARGUMENT) {
			decl.append("::");
		} else if (o.getHasArg() == LongOpt.REQUIRED_ARGUMENT) {
			decl.append(":");
		}
	}
	Getopt g = new Getopt("anyurl", args, decl.toString(), options);
	 
	int c= 0;
	while ((c = g.getopt()) != -1) {
		LongOpt opt = shortOptionMap.get(c);
		String optName = opt.getName();
		String optVal = g.getOptarg();
		props.put(optName, optVal);
	}
	
	// NB: Getopt moves non options to the end
	return Arrays.copyOfRange(args, g.getOptind(), args.length);
}
 
开发者ID:bhabegger,项目名称:anyurl,代码行数:31,代码来源:App.java

示例9: processCommandLine

import gnu.getopt.LongOpt; //导入依赖的package包/类
private void processCommandLine(String[] args) {

        String programName = System.getProperty("program.name", "Mobicents Media Server");

        int c;
        String arg;
        LongOpt[] longopts = new LongOpt[2];
        longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
        longopts[1] = new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'b');

        Getopt g = new Getopt("SMSC", args, "-:b:h", longopts);
        g.setOpterr(false); // We'll do our own error handling
        //
        while ((c = g.getopt()) != -1) {
            switch (c) {

                //
                case 'b':
                    arg = g.getOptarg();
                    System.setProperty(SMSC_BIND_ADDRESS, arg);

                    break;
                //

                case 'h':
                    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("    -b, --host=<host or ip>       Bind address for all Mobicents SMSC services");
                    System.out.println();
                    System.exit(0);
                    break;

                case ':':
                    System.out.println("You need an argument for option " + (char) g.getOptopt());
                    System.exit(0);
                    break;
                //
                case '?':
                    System.out.println("The option '" + (char) g.getOptopt() + "' is not valid");
                    System.exit(0);
                    break;
                //
                default:
                    System.out.println("getopt() returned " + c);
                    break;
            }
        }

        if (System.getProperty(SMSC_BIND_ADDRESS) == null) {
            System.setProperty(SMSC_BIND_ADDRESS, "127.0.0.1");
        }

    }
 
开发者ID:RestComm,项目名称:camelgateway,代码行数:56,代码来源:Main.java

示例10: getConfigFromArgv

import gnu.getopt.LongOpt; //导入依赖的package包/类
public static boolean getConfigFromArgv(String argv[])
{

    int c;
    String arg;

    LongOpt [] longopts = new LongOpt[10];
    longopts[0] = new LongOpt(SERVER_MODE, LongOpt.NO_ARGUMENT, null, 'S');
    longopts[1] = new LongOpt(METHOD, LongOpt.REQUIRED_ARGUMENT, null, 'm');
    longopts[2] = new LongOpt(PASSWORD, LongOpt.REQUIRED_ARGUMENT, null, 'k');
    longopts[3] = new LongOpt(SERVER_PORT, LongOpt.REQUIRED_ARGUMENT, null, 'p');
    longopts[4] = new LongOpt(AUTH, LongOpt.NO_ARGUMENT, null, 'a');
    longopts[5] = new LongOpt(SERVER_ADDR, LongOpt.REQUIRED_ARGUMENT, null, 's');
    longopts[6] = new LongOpt(LOCAL_PORT, LongOpt.REQUIRED_ARGUMENT, null, 'l');
    longopts[7] = new LongOpt(CONFIG, LongOpt.REQUIRED_ARGUMENT, null, 'c');
    longopts[8] = new LongOpt(TIMEOUT, LongOpt.REQUIRED_ARGUMENT, null, 't');
    longopts[9] = new LongOpt(HELP, LongOpt.NO_ARGUMENT, null, 'h');

    Getopt g = new Getopt("shadowsocks", argv, "Sm:k:p:as:l:c:t:h", longopts);

    while ((c = g.getopt()) != -1)
    {
        switch(c)
        {
            case 'm':
                arg = g.getOptarg();
                log.debug("CMD:Crypto method: " + arg);
                GlobalConfig.get().setMethod(arg);
                break;
            case 'k':
                arg = g.getOptarg();
                log.debug("CMD:Password: " + arg);
                GlobalConfig.get().setPassowrd(arg);
                break;
            case 'p':
                arg = g.getOptarg();
                int port = Integer.parseInt(arg);
                log.debug("CMD:Server port: " + port);
                GlobalConfig.get().setPort(port);
                break;
            case 'a':
                log.debug("CMD:OTA enforcing mode.");
                GlobalConfig.get().setOTAEnabled(true);
                break;
            case 'S':
                log.debug("CMD:Server mode.");
                GlobalConfig.get().setServerMode(true);
                break;
            case 's':
                arg = g.getOptarg();
                log.debug("CMD:Server address: " + arg);
                GlobalConfig.get().setServer(arg);
                break;
            case 'l':
                arg = g.getOptarg();
                int lport = Integer.parseInt(arg);
                log.debug("CMD:Local port: " + lport);
                GlobalConfig.get().setLocalPort(lport);
                break;
            case 'c':
                arg = g.getOptarg();
                log.debug("CMD:Config file: " + arg);
                GlobalConfig.get().setConfigFile(arg);
                break;
            case 't':
                arg = g.getOptarg();
                int timeout = Integer.parseInt(arg);
                log.debug("CMD:timeout: " + timeout);
                GlobalConfig.get().setTimeout(timeout);
                break;
            case 'h':
            case '?':
            default:
                help();
                return false;
        }
    }
    return true;
}
 
开发者ID:Bestoa,项目名称:shadowsocks-vertx,代码行数:80,代码来源:GlobalConfig.java

示例11: main

import gnu.getopt.LongOpt; //导入依赖的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

示例12: parseArguments

import gnu.getopt.LongOpt; //导入依赖的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

示例13: getLongOptions

import gnu.getopt.LongOpt; //导入依赖的package包/类
/**
 * @return the longOptions
 */
public LongOpt[] getLongOptions() {
    return longOptions;
}
 
开发者ID:imagopole,项目名称:omero-csv-tools,代码行数:7,代码来源:AbstractArgsParser.java

示例14: setLongOptions

import gnu.getopt.LongOpt; //导入依赖的package包/类
/**
 * @param longOptions the longOptions to set
 */
public void setLongOptions(LongOpt[] longOptions) {
    this.longOptions = longOptions;
}
 
开发者ID:imagopole,项目名称:omero-csv-tools,代码行数:7,代码来源:AbstractArgsParser.java

示例15: printHelp

import gnu.getopt.LongOpt; //导入依赖的package包/类
private void printHelp(LongOpt[] longOpts) {
	for (LongOpt opt : longOpts) {
		System.out.printf("-%s --%s <%s>\n", (char) opt.getVal(), opt.getName(),
			opt.getHasArg() == LongOpt.OPTIONAL_ARGUMENT ? "optional" : "required");
	}
}
 
开发者ID:singularsyntax,项目名称:concurrency-utils,代码行数:7,代码来源:Benchmark.java


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