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


Java Getopt.setOpterr方法代码示例

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


在下文中一共展示了Getopt.setOpterr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: processCommandLine

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

示例3: 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


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