Class Getopt

java.lang.Object
org.opengrok.indexer.util.Getopt

public class Getopt extends 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 Details

    • Getopt

      public Getopt(String[] argv, String opts)
      Creates a new instance of Getopt.
      Parameters:
      argv - argument vector
      opts - the list of allowed options
  • Method Details

    • parse

      public void parse() throws ParseException
      Parse the command line options.
      Throws:
      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 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