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.
-
-
-
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 lineparams
- 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 interfaceEnvironment
- 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 interfaceEnvironment
- 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 interfaceEnvironment
- Returns:
- array of names of known supplied parameters
-
getOutputStream
public java.io.PrintStream getOutputStream()
Returns System.out.- Specified by:
getOutputStream
in interfaceEnvironment
- Returns:
- System.out
-
getErrorStream
public java.io.PrintStream getErrorStream()
Returns System.err.- Specified by:
getErrorStream
in interfaceEnvironment
- Returns:
- System.err
-
-