Package uk.ac.starlink.task
Class TerminalInvoker
java.lang.Object
uk.ac.starlink.task.TerminalInvoker
Invokes Task objects in a way suitable for use from the main
method, using a command line interface.
The Task invoke methods are invoked and may throw any exception;
UsageException
and ExecutionException
will be treated
specially (a sanitised error message without stacktrace will be
presented to the user).- Author:
- Mark Taylor (Starlink)
-
Constructor Summary
ConstructorsConstructorDescriptionTerminalInvoker
(String toolname, Map<String, Task> taskmap) Creates a new invoker based on the given class with a given name. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getTaskUsage
(Task task) Returns a usage string for a given task.void
Invokes a method from this TerminalInvoker's class.
-
Constructor Details
-
TerminalInvoker
Creates a new invoker based on the given class with a given name. This should generally be invoked from a main method - in the event of an error it will call System.exit rather than returning.- Parameters:
toolname
- the name of this tool, used for user messagestaskmap
- map of task names to Task objects
-
-
Method Details
-
invoke
Invokes a method from this TerminalInvoker's class. The first element of the args identifies the method to be called - it is a case-insensitive version of the name of a method in the class. Subsequent elements are passed (as an args.length-1 element array of Strings) to the method in question. In the event of any trouble (e.g. unknown task, task method throws an exception) a message is printed to standard error and the JVM exits.- Parameters:
args
- the arguments identifying what method to call and what arguments to pass to it- Throws:
Exception
-
getTaskUsage
Returns a usage string for a given task. This contains only a symbolic representation of the parameter names, not the task name itself.- Parameters:
task
- task- Returns:
- usage string
-