Package uk.ac.starlink.task

## Class TerminalEnvironment

- java.lang.Object
- - uk.ac.starlink.task.TerminalEnvironment

- All Implemented Interfaces:
    `Environment`

      public class TerminalEnvironment
      extends java.lang.Object
      implements Environment

  Implementation of Environment which accepts an initial command line, and communicates with the user using standard input and standard output.

  This environment is somewhat deprecated in favour of the more capable `LineEnvironment`.

  Author:
    Mark Taylor (Starlink)

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `NUM_TRIES` | The number of goes you get to put in an invalid parameter.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `TerminalEnvironment​(java.lang.String[] args, Parameter<?>[] params)` | Constructs a new Environment based on a String array containing supplied arguments, and a list of parameters which may be encountered.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `acquireValue​(Parameter<?> par)` | Sets the value of a parameter.
    `void` | `clear​(Parameter<?> par)` |
    `void` | `clearValue​(Parameter<?> par)` | Clears a value for a given parameter.
    `java.io.PrintStream` | `getErrorStream()` | Returns `System.err`.
    `java.lang.String[]` | `getNames()` | Returns an array of parameter names which have been specified.
    `java.io.PrintStream` | `getOutputStream()` | Returns `System.out`.

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

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

- - ### Field Detail

    - #### NUM_TRIES

          public static int NUM_TRIES

      The number of goes you get to put in an invalid parameter.

  - ### Constructor Detail

    - #### TerminalEnvironment

          public TerminalEnvironment​(java.lang.String[] args,
                                     Parameter<?>[] params)
                              throws UsageException

      Constructs a new Environment based on a String array containing supplied arguments, and a list of parameters which may be encountered. The initial arguments may have the form `value` or `name=value`; in the former case they must correspond to a parameter with a non-zero position attribute indicating where it is expected on the command line, and in the latter case the `name` must correspond to the name of one of the parameters in `params`.
      Parameters:
        `args` - an array of words found on the command line
        `params` - an array of Parameter objects which this Environment may be asked to get values for
      Throws:
        `UsageException`

  - ### Method Detail

    - #### clear

          public void clear​(Parameter<?> par)

    - #### acquireValue

          public void acquireValue​(Parameter<?> par)
                            throws TaskException

      Sets the value of a parameter. If it a value has been specified on the command line then that is used, otherwise any known default is used, otherwise the user is prompted on standard output and response got from standard input.

      A more configurable order (cf ADAM PPATH/VPATH) could be implemented by adding some methods to Parameter and getting this method to query them.

      Specified by:
        `acquireValue` in interface `Environment`
      Parameters:
        `par` - the parameter whose value is to be set
      Throws:
        `TaskException`

    - #### clearValue

          public void clearValue​(Parameter<?> par)

      Description copied from interface: `Environment`
      Clears a value for a given parameter.
      Specified by:
        `clearValue` in interface `Environment`
      Parameters:
        `par` - the Parameter whose value is to be cleared

    - #### getNames

          public java.lang.String[] getNames()

      Description copied from interface: `Environment`
      Returns an array of parameter names which have been specified. The result is not necessarily an exhaustive list of all parameters whose values can be retrieved from this environment, since an interactive environment may be able to prompt the user for values, but it can give a list of values provided explicitly or without interactive prompts.
      Specified by:
        `getNames` in interface `Environment`
      Returns:
        array of names of known supplied parameters

    - #### getOutputStream

          public java.io.PrintStream getOutputStream()

      Returns `System.out`.
      Specified by:
        `getOutputStream` in interface `Environment`
      Returns:
        System.out

    - #### getErrorStream

          public java.io.PrintStream getErrorStream()

      Returns `System.err`.
      Specified by:
        `getErrorStream` in interface `Environment`
      Returns:
        System.err