Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.ifs.utils.cmd
Class OptionParser

    java.lang.Object
      oracle.ifs.utils.cmd.OptionParser

    public class OptionParser

extends java.lang.Object

The `OptionParser` class provides facilities to parse command line options.
Example:

>      public static void main(String[] args) {
>        // options v and O may be clumped, as in "-vO"
>        BooleanOption     v         = new BooleanOption("v"); // verbose
>        BooleanOption     O         = new BooleanOption("O"); // optimize
>        BooleanOption     nowarn    = new BooleanOption("nowarn"); // don't warn
>        StringOption      classpath = new StringOption("classpath"); // explicit classpath
>        StringClumpOption logfile   = new StringClumpOption("logfile="); // logfile

>        try {
>          OptionParser parser =
>            new OptionParser(new CmdLineOption[]{opt1, opt2, opt3, opt4, opt5});
>          int nIndexAfterOptions = parser.parse(args);

>          if (v.value) System.out.println("Verbose set");
>          else System.out.println("Verbose not set");
>          if (O.value) System.out.println("Optimize");
>          else System.out.println("Don't optimize");
>          if (nowarn.value) System.out.println("Don't warn");
>          else System.out.println("Warn");
>          if (null == classpath.value) System.out.println("Classpath not set");
>          else System.out.println("Classpath: " + classpath.value);
>          if (null == logfile.value) System.out.println("No logfile specified");
>          else System.out.println("Logfile: " + logfile.value);
>          System.out.println("First non-option argument: " +
>                             Integer.toString(nIndexAfterOptions));
>        }
>        catch (BadCommandLineException e) {
>          System.out.println("usage()\n" + e);
>        }
>        catch (InvalidOptionException e) {
>          System.out.println("bad options specified: " + e);
>        }
>      }

See Also:
  `BooleanOption`, `StringOption`, `StringClumpOption`
Modified:
  jbaccash 07/26/2000 Created.

Constructor Summary
`OptionParser(CmdLineOption[] options)` Creates a new command line option parser based on the given options.

Method Summary
`int` | `parse(java.lang.String[] args)` Parses a command line for options, looking for longest match first.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### OptionParser

    public OptionParser(CmdLineOption[] options)
                 throws InvalidOptionException

  Creates a new command line option parser based on the given options.

  Parameters:
    `options` - the array of options.
  Throws:
    `InvalidOptionException` - if two options have the same key or one key equals "-".

Method Detail

### parse

    public int parse(java.lang.String[] args)
              throws BadCommandLineException

  Description copied from class: `OptionParser`
  Parses a command line for options, looking for longest match first.

  Parameters:
    `args` - the command line arguments to parse.
  Returns:
    an index to the first command line argument that is not an option. i.e., the first argument that does not begin with "-", or the argument following the first argument that equals "--".
  Throws:
    `BadCommandLineException` - if there is an illegal option on the command line.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD