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


Java LongOpt.OPTIONAL_ARGUMENT属性代码示例

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


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

示例1: getShortOpts

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,代码行数:26,代码来源:Main.java

示例2: getShortOptions

/**
 * 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,代码行数:24,代码来源:PlanetCLI.java

示例3: usage

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,代码行数:36,代码来源:Main.java

示例4: createLongOpts

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,代码行数:12,代码来源:WolpertingerCli.java

示例5: processOption

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,代码行数:30,代码来源:App.java

示例6: main

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,代码行数:80,代码来源:GetoptDemo.java

示例7: readParameters

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,代码行数:74,代码来源:AlignmentClient.java

示例8: run

public void run(String[] args) throws Exception {
String listFile = "";
LongOpt[] longopts = new LongOpt[10];

	longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o');
longopts[2] = new LongOpt("format", LongOpt.REQUIRED_ARGUMENT, null, 'f');
longopts[3] = new LongOpt("type", LongOpt.REQUIRED_ARGUMENT, null, 't');
longopts[4] = new LongOpt("debug", LongOpt.OPTIONAL_ARGUMENT, null, 'd');
longopts[5] = new LongOpt("sup", LongOpt.REQUIRED_ARGUMENT, null, 's');
longopts[6] = new LongOpt("list", LongOpt.REQUIRED_ARGUMENT, null, 'l');
longopts[7] = new LongOpt("color", LongOpt.OPTIONAL_ARGUMENT, null, 'c');
longopts[8] = new LongOpt("reference", LongOpt.REQUIRED_ARGUMENT, null, 'r');
longopts[9] = new LongOpt("directory", LongOpt.REQUIRED_ARGUMENT, null, 'w');

Getopt g = new Getopt("", args, "ho:a:d::l:f:t:r:w:c::", longopts);
int c;
String arg;

while ((c = g.getopt()) != -1) {
    switch (c) {
    case 'h' :
	usage();
	return;
    case 'o' :
	/* Write output here */
	filename = g.getOptarg();
	break;
    case 'r' :
	/* File name for the reference alignment */
	reference = g.getOptarg();
	break;
    case 'f' :
	/* Sequence of results to print */
	format = g.getOptarg();
	break;
    case 't' :
	/* Type of output (tex/html/xml/ascii) */
	type = g.getOptarg();
	break;
    case 's' :
	/* Print per type or per algo */
	dominant = g.getOptarg();
	break;
    case 'c' :
	/* Print colored lines */
	color = "lightblue";
	    //dominant = g.getOptarg();
	break;
    case 'l' :
	/* List of filename */
	listFile = g.getOptarg();
	break;
    case 'd' :
	/* Debug level  */
	arg = g.getOptarg();
	if ( arg != null ) debug = Integer.parseInt(arg.trim());
	else debug = 4;
	break;
    case 'w' :
	/* Use the given ontology directory */
    arg = g.getOptarg();
    if ( arg != null ) ontoDir = g.getOptarg();
    else ontoDir = null;
	break;
    }
}

listAlgo = new Vector<String>();
for ( String s : listFile.split(",") ) {
    listAlgo.add( s );	    
}

params = new Properties();
if (debug > 0) params.setProperty( "debug", Integer.toString( debug-1 ) );

print( iterateDirectories() );
   }
 
开发者ID:dozed,项目名称:align-api-project,代码行数:78,代码来源:ExtGroupEval.java

示例9: run

public void run(String[] args) throws Exception {
String listFile = "";
LongOpt[] longopts = new LongOpt[10];

	longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o');
longopts[2] = new LongOpt("format", LongOpt.REQUIRED_ARGUMENT, null, 'f');
longopts[3] = new LongOpt("type", LongOpt.REQUIRED_ARGUMENT, null, 't');
longopts[4] = new LongOpt("debug", LongOpt.OPTIONAL_ARGUMENT, null, 'd');
longopts[5] = new LongOpt("sup", LongOpt.REQUIRED_ARGUMENT, null, 's');
longopts[6] = new LongOpt("list", LongOpt.REQUIRED_ARGUMENT, null, 'l');
longopts[7] = new LongOpt("color", LongOpt.OPTIONAL_ARGUMENT, null, 'c');
longopts[8] = new LongOpt("reference", LongOpt.REQUIRED_ARGUMENT, null, 'r');
longopts[9] = new LongOpt("directory", LongOpt.REQUIRED_ARGUMENT, null, 'w');

Getopt g = new Getopt("", args, "ho:a:d::l:f:t:r:w:c::", longopts);
int c;
String arg;

while ((c = g.getopt()) != -1) {
    switch (c) {
    case 'h' :
	usage();
	return;
    case 'o' :
	/* Write output here */
	filename = g.getOptarg();
	break;
    case 'r' :
	/* File name for the reference alignment */
	reference = g.getOptarg();
	break;
    case 'f' :
	/* Sequence of results to print */
	format = g.getOptarg();
	break;
    case 't' :
	/* Type of output (tex/html/xml/ascii) */
	type = g.getOptarg();
	break;
    case 's' :
	/* Print per type or per algo */
	dominant = g.getOptarg();
	break;
    case 'c' :
	/* Print colored lines */
	arg = g.getOptarg();
	if ( arg != null )  {
	    color = arg.trim();
	} else color = "lightblue";
	break;
    case 'l' :
	/* List of filename */
	listFile = g.getOptarg();
	break;
    case 'd' :
	/* Debug level  */
	arg = g.getOptarg();
	if ( arg != null ) debug = Integer.parseInt(arg.trim());
	else debug = 4;
	break;
    case 'w' :
	/* Use the given ontology directory */
    arg = g.getOptarg();
    if ( arg != null ) ontoDir = g.getOptarg();
    else ontoDir = null;
	break;
    }
}

listAlgo = new Vector<String>();
for ( String s : listFile.split(",") ) {
    listAlgo.add( s );	    
}

params = new Properties();
if (debug > 0) params.setProperty( "debug", Integer.toString( debug-1 ) );

print( iterateDirectories() );
   }
 
开发者ID:dozed,项目名称:align-api-project,代码行数:80,代码来源:GroupEval.java


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