Command (API documentation of hlt.language packages)
Date: 2013-01-30

hlt.language.tools

## Class Command

- java.lang.Object
- - hlt.language.tools.Command

- Direct Known Subclasses:
    GenericHiliteCommand, HiliteCommand, Jacc

      public class Command
      extends java.lang.Object

  This class implements a simple UNIX style command parser. It is meant to be subclassed or used directly through its static methods (which is why it has no constructor). Its method `parseCommandLine(String[])` takes the array of strings on command line (i.e., the argument of a `main` method) and determines which options are used with what values. It also defines a few utilities (1) to set and access the values of the options and arguments specified in the parsed command, (2) to determine if these are present, and (3) to do simple file name completion.
  Version:
    Last modified on Fri Apr 13 19:43:43 2012 by hak
  Author:
    Hassan Aït-Kaci
  Copyright:
    © by the author

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Command()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `argumentIsPresent()` Returns true iff an argument is actually present on the command line.
    `static java.lang.String` | `completeFileName(java.lang.String name, java.lang.String ext)` Returns a file's name completed with its extension if the latter is missing.
    `static void` | `defineOption(java.lang.String option, java.lang.String defaultValue)` Defines an option with a default value.
    `static void` | `defineOption(java.lang.String option, java.lang.String defaultValue, java.lang.String help)` Defines an option with a default value and description.
    `static java.lang.String` | `fileNameDir(java.lang.String name)` Returns a file's name's directory part.
    `static java.lang.String` | `fileNamePrefix(java.lang.String name)` Returns a file's name without its extension nor its directory path.
    `static java.lang.String` | `fileNameSuffix(java.lang.String name)` Returns a file's name extension.
    `static java.lang.String` | `fullFileNamePrefix(java.lang.String name)` Returns a file's name without its extension, but including its directory path.
    `static java.lang.String` | `getArgument()` Returns the value of the argument.
    `static java.lang.String[]` | `getArguments()` Returns the array of values of all the arguments.
    `static java.lang.String` | `getOption(java.lang.String option)` Returns the value associated with an option.
    `static java.lang.String` | `getUsage()`
    `static void` | `optionalArgument(java.lang.String arg)` Sets the default argument to the specified string.
    `static boolean` | `optionIsPresent(java.lang.String option)` Returns true iff the option is actually present on the command line.
    `static boolean` | `parseCommandLine(java.lang.String[] args)` Parses the command line recognizing the defined options and the arguments, and storing their specified values as appropriate.
    `static void` | `printHelp()` Prints a listing of known options, their defaults, and descriptions.
    `static void` | `printUsage()`
    `static void` | `setUsage(java.lang.String usg)`

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

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

- - ### Constructor Detail

    - #### Command

          public Command()

  - ### Method Detail

    - #### optionalArgument

          public static final void optionalArgument(java.lang.String arg)

      Sets the default argument to the specified string.
      Parameters:
        `arg` - value to use if the command argument is missing

    - #### defineOption

          public static final void defineOption(java.lang.String option,
                          java.lang.String defaultValue)

      Defines an option with a default value.
      Parameters:
        `option` - the option string
        `defaultValue` - the option's default

    - #### defineOption

          public static final void defineOption(java.lang.String option,
                          java.lang.String defaultValue,
                          java.lang.String help)

      Defines an option with a default value and description.
      Parameters:
        `option` - the option string
        `defaultValue` - the option's default
        `help` - option's description

    - #### getOption

          public static final java.lang.String getOption(java.lang.String option)

      Returns the value associated with an option. If the option is undefined, a `CommandException` is reported.
      Parameters:
        `option` - the option

    - #### optionIsPresent

          public static final boolean optionIsPresent(java.lang.String option)

      Returns true iff the option is actually present on the command line. If the option is undefined, a `CommandException` is reported.
      Parameters:
        `option` - the option

    - #### getArgument

          public static final java.lang.String getArgument()

      Returns the value of the argument. If none is specified, returns the default argument. If many are specified, the first is returned.

    - #### getArguments

          public static final java.lang.String[] getArguments()

      Returns the array of values of all the arguments. If none is specified, returns a one element array containing the default argument.

    - #### argumentIsPresent

          public static final boolean argumentIsPresent()

      Returns true iff an argument is actually present on the command line.

    - #### fullFileNamePrefix

          public static final java.lang.String fullFileNamePrefix(java.lang.String name)

      Returns a file's name without its extension, but including its directory path.
      Parameters:
        `name` - the file's name

    - #### fileNamePrefix

          public static final java.lang.String fileNamePrefix(java.lang.String name)

      Returns a file's name without its extension nor its directory path.
      Parameters:
        `name` - the file's name

    - #### fileNameDir

          public static final java.lang.String fileNameDir(java.lang.String name)

      Returns a file's name's directory part.
      Parameters:
        `name` - the file's name

    - #### fileNameSuffix

          public static final java.lang.String fileNameSuffix(java.lang.String name)

      Returns a file's name extension.
      Parameters:
        `name` - the file's name

    - #### completeFileName

          public static final java.lang.String completeFileName(java.lang.String name,
                                          java.lang.String ext)

      Returns a file's name completed with its extension if the latter is missing.
      Parameters:
        `name` - the file's name
        `ext` - the file's extension

    - #### getUsage

          public static java.lang.String getUsage()

    - #### setUsage

          public static void setUsage(java.lang.String usg)

    - #### printUsage

          public static void printUsage()

    - #### printHelp

          public static final void printHelp()

      Prints a listing of known options, their defaults, and descriptions.

    - #### parseCommandLine

          public static final boolean parseCommandLine(java.lang.String[] args)

      Parses the command line recognizing the defined options and the arguments, and storing their specified values as appropriate. Note that if the same option is specified more than once on the command line, only the last one is effective.