Package uk.ac.starlink.task
Class TerminalEnvironment
java.lang.Object
uk.ac.starlink.task.TerminalEnvironment
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic int
The number of goes you get to put in an invalid parameter. -
Constructor Summary
ConstructorsConstructorDescriptionTerminalEnvironment
(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
Modifier and TypeMethodDescriptionvoid
acquireValue
(Parameter<?> par) Sets the value of a parameter.void
void
clearValue
(Parameter<?> par) Clears a value for a given parameter.Returns System.err.String[]
getNames()
Returns an array of parameter names which have been specified.Returns System.out.
-
Field Details
-
NUM_TRIES
public static int NUM_TRIESThe number of goes you get to put in an invalid parameter.
-
-
Constructor Details
-
TerminalEnvironment
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 Details
-
clear
-
acquireValue
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
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
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
Returns System.out.- Specified by:
getOutputStream
in interfaceEnvironment
- Returns:
- System.out
-
getErrorStream
Returns System.err.- Specified by:
getErrorStream
in interfaceEnvironment
- Returns:
- System.err
-