org.opensolaris.opengrok.util
Class Getopt

java.lang.Object
  extended by org.opensolaris.opengrok.util.Getopt

public class Getopt
extends java.lang.Object

A simple implementation of the getopt(3c). It does just implement what I need ;-) Please note that I dislike the way GNU getopt allows mixing of options and arguments, so this version will stop processing options as soon as it encounters an argument.


Constructor Summary
Getopt(java.lang.String[] argv, java.lang.String opts)
          Creates a new instance of Getopt
 
Method Summary
 int getOpt()
          Get the next option in the options string.
 java.lang.String getOptarg()
          Get the argument to the current option
 int getOptind()
          Get the index of the first argument
 void parse()
          Parse the command lineoptions
 void reset()
          Reset the current pointer so we may traverse all the options again..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Getopt

public Getopt(java.lang.String[] argv,
              java.lang.String opts)
Creates a new instance of Getopt

Parameters:
argv - argument vector
opts - the list of allowed options
Method Detail

parse

public void parse()
           throws java.text.ParseException
Parse the command lineoptions

Throws:
java.text.ParseException - if an illegal argument is passed

getOpt

public int getOpt()
Get the next option in the options string.

Returns:
the next valid option, or -1 if all options are processed

reset

public void reset()
Reset the current pointer so we may traverse all the options again..


getOptarg

public java.lang.String getOptarg()
Get the argument to the current option

Returns:
the argument or null if none present (or allowed)

getOptind

public int getOptind()
Get the index of the first argument

Returns:
the index of the first argument in the original array