Package jargs.gnu

## Class CmdLineParser

- java.lang.Object
- - jargs.gnu.CmdLineParser

-     public class CmdLineParser
      extends Object

  Largely GNU-compatible command-line options parser. Has short (-v) and long-form (--verbose) option support, and also allows options with associated values (-d 2, --debug 2, --debug=2). Option processing can be explicitly terminated by the argument '--'.
  Version:
    $Revision$
  Author:
    Steve Purcell
  See Also:
    jargs examples

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `CmdLineParser.IllegalOptionValueException` | Thrown when an illegal or missing value is given by the user for an option that takes a value.
    `static class` | `CmdLineParser.NotFlagException` | Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one or more requires a value.
    `static class` | `CmdLineParser.Option` | Representation of a command-line option.
    `static class` | `CmdLineParser.OptionException` | Base class for exceptions that may be thrown when options are parsed.
    `static class` | `CmdLineParser.UnknownOptionException` | Thrown when the parsed command-line contains an option that is not recognised.
    `static class` | `CmdLineParser.UnknownSuboptionException` | Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one is unknown.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CmdLineParser()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `CmdLineParser.Option` | `addBooleanOption​(char shortForm, String longForm)` | Convenience method for adding a boolean option.
    `CmdLineParser.Option` | `addBooleanOption​(String longForm)` | Convenience method for adding a boolean option.
    `CmdLineParser.Option` | `addDoubleOption​(char shortForm, String longForm)` | Convenience method for adding a double option.
    `CmdLineParser.Option` | `addDoubleOption​(String longForm)` | Convenience method for adding a double option.
    `CmdLineParser.Option` | `addIntegerOption​(char shortForm, String longForm)` | Convenience method for adding an integer option.
    `CmdLineParser.Option` | `addIntegerOption​(String longForm)` | Convenience method for adding an integer option.
    `CmdLineParser.Option` | `addLongOption​(char shortForm, String longForm)` | Convenience method for adding a long integer option.
    `CmdLineParser.Option` | `addLongOption​(String longForm)` | Convenience method for adding a long integer option.
    `CmdLineParser.Option` | `addOption​(CmdLineParser.Option opt)` | Add the specified Option to the list of accepted options.
    `CmdLineParser.Option` | `addStringOption​(char shortForm, String longForm)` | Convenience method for adding a string option.
    `CmdLineParser.Option` | `addStringOption​(String longForm)` | Convenience method for adding a string option.
    `Object` | `getOptionValue​(CmdLineParser.Option o)` | Equivalent to `getOptionValue(o, null)`.
    `Object` | `getOptionValue​(CmdLineParser.Option o, Object def)` | Gets the option value.
    `List<String>` | `getOptionValues​(CmdLineParser.Option option)` | Gets the option values.
    `List<String>` | `getRemainingArgs()` | Gets the remaining args.
    `void` | `parse​(String[] argv)` | Extract the options and non-option arguments from the given list of command-line arguments.
    `void` | `parse​(String[] argv, Locale locale)` | Extract the options and non-option arguments from the given list of command-line arguments.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CmdLineParser

          public CmdLineParser()

  - ### Method Detail

    - #### addOption

          public final CmdLineParser.Option addOption​(CmdLineParser.Option opt)

      Add the specified Option to the list of accepted options.
      Parameters:
        `opt` - the opt
      Returns:
        the option

    - #### addStringOption

          public final CmdLineParser.Option addStringOption​(char shortForm,
                                                            String longForm)

      Convenience method for adding a string option.
      Parameters:
        `shortForm` - the short form
        `longForm` - the long form
      Returns:
        the new Option

    - #### addStringOption

          public final CmdLineParser.Option addStringOption​(String longForm)

      Convenience method for adding a string option.
      Parameters:
        `longForm` - the long form
      Returns:
        the new Option

    - #### addIntegerOption

          public final CmdLineParser.Option addIntegerOption​(char shortForm,
                                                             String longForm)

      Convenience method for adding an integer option.
      Parameters:
        `shortForm` - the short form
        `longForm` - the long form
      Returns:
        the new Option

    - #### addIntegerOption

          public final CmdLineParser.Option addIntegerOption​(String longForm)

      Convenience method for adding an integer option.
      Parameters:
        `longForm` - the long form
      Returns:
        the new Option

    - #### addLongOption

          public final CmdLineParser.Option addLongOption​(char shortForm,
                                                          String longForm)

      Convenience method for adding a long integer option.
      Parameters:
        `shortForm` - the short form
        `longForm` - the long form
      Returns:
        the new Option

    - #### addLongOption

          public final CmdLineParser.Option addLongOption​(String longForm)

      Convenience method for adding a long integer option.
      Parameters:
        `longForm` - the long form
      Returns:
        the new Option

    - #### addDoubleOption

          public final CmdLineParser.Option addDoubleOption​(char shortForm,
                                                            String longForm)

      Convenience method for adding a double option.
      Parameters:
        `shortForm` - the short form
        `longForm` - the long form
      Returns:
        the new Option

    - #### addDoubleOption

          public final CmdLineParser.Option addDoubleOption​(String longForm)

      Convenience method for adding a double option.
      Parameters:
        `longForm` - the long form
      Returns:
        the new Option

    - #### addBooleanOption

          public final CmdLineParser.Option addBooleanOption​(char shortForm,
                                                             String longForm)

      Convenience method for adding a boolean option.
      Parameters:
        `shortForm` - the short form
        `longForm` - the long form
      Returns:
        the new Option

    - #### addBooleanOption

          public final CmdLineParser.Option addBooleanOption​(String longForm)

      Convenience method for adding a boolean option.
      Parameters:
        `longForm` - the long form
      Returns:
        the new Option

    - #### getOptionValue

          public final Object getOptionValue​(CmdLineParser.Option o)

      Equivalent to `getOptionValue(o, null)`.
      Parameters:
        `o` - the o
      Returns:
        the option value

    - #### getOptionValue

          public final Object getOptionValue​(CmdLineParser.Option o,
                                             Object def)

      Gets the option value.
      Parameters:
        `o` - the o
        `def` - the def
      Returns:
        the parsed value of the given Option, or the given default 'def' if the option was not set

    - #### getOptionValues

          public final List<String> getOptionValues​(CmdLineParser.Option option)

      Gets the option values.
      Parameters:
        `option` - the option
      Returns:
        A Vector giving the parsed values of all the occurrences of the given Option, or an empty Vector if the option was not set.

    - #### getRemainingArgs

          public final List<String> getRemainingArgs()

      Gets the remaining args.
      Returns:
        the non-option arguments

    - #### parse

          public final void parse​(String[] argv)
                           throws CmdLineParser.IllegalOptionValueException,
                                  CmdLineParser.UnknownOptionException

      Extract the options and non-option arguments from the given list of command-line arguments. The default locale is used for parsing options whose values might be locale-specific.
      Parameters:
        `argv` - the argv
      Throws:
        `CmdLineParser.IllegalOptionValueException` - the illegal option value exception
        `CmdLineParser.UnknownOptionException` - the unknown option exception

    - #### parse

          public final void parse​(String[] argv,
                                  Locale locale)
                           throws CmdLineParser.IllegalOptionValueException,
                                  CmdLineParser.UnknownOptionException

      Extract the options and non-option arguments from the given list of command-line arguments. The specified locale is used for parsing options whose values might be locale-specific.
      Parameters:
        `argv` - the argv
        `locale` - the locale
      Throws:
        `CmdLineParser.IllegalOptionValueException` - the illegal option value exception
        `CmdLineParser.UnknownOptionException` - the unknown option exception