Package com.e1c.g5.v8.dt.cli.api
Interface ICliSession
-
public interface ICliSession
Session information and special functions. To get an instance of this class, just declare a parameter of this type in you command's method:
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
criticalSection(Runnable task)
Runs code in a critical section.<T> T
criticalSection(Callable<T> task)
Runs code in a critical section.String
getCommandLine()
Returns the unparsed command line which is being executed now.String
getCommandName()
Returns the name of the command being executed.Map<String,Object>
getRawCommandArguments()
Returns the raw (unprocessed) arguments of the command being executed.Object
getVariable(String name)
Get the value of a variable.Set<String>
getVariables()
Returns all variable names.Object
putVariable(String name, Object value)
Set the value of a variable.String
readLine(String printMessage)
Reads a line of user input from the console:
-
-
-
Method Detail
-
criticalSection
<T> T criticalSection(Callable<T> task) throws Exception
Runs code in a critical section. Command execution will not be terminated by timeout while inside of a critical section. The timeout restarts when the execution leaves the critical section.- Type Parameters:
T
- critical section return type.- Parameters:
task
- task to run in a critical section. It will run in the same thread.- Returns:
- return value of the task.
- Throws:
Exception
- if the task throws exception, it will be thrown from this method.- See Also:
criticalSection(Runnable)
-
criticalSection
void criticalSection(Runnable task)
Runs code in a critical section. Command execution will not be terminated by timeout while inside of a critical section. The timeout restarts when the execution leaves the critical section.- Parameters:
task
- task to run in a critical section. It will run in the same thread.- Throws:
RuntimeException
- if the task throws exception, it will be thrown from this method.- See Also:
criticalSection(Callable)
-
readLine
String readLine(String printMessage) throws IOException
Reads a line of user input from the console:
This method prints the optional message to console and blocks until the user presses Enter. Then it returns the line user entered. This method does not count to the command's timeout. Do not wrap it inString userName = session.readLine("Please enter your name: "); ...
criticalSection(Callable)
.- Parameters:
printMessage
- optional message to print to the user before waiting for their input. May benull
.- Returns:
- A String containing the contents of the line user entered, not including any line-termination characters.
May be
null
, if the end of the console stream has been reached without reading any characters. - Throws:
IOException
-
getVariable
Object getVariable(String name)
Get the value of a variable.- Parameters:
name
- name of the variable.- Returns:
- variable value, or
null
.
-
getVariables
Set<String> getVariables()
Returns all variable names.- Returns:
- variable names, never
null
.
-
putVariable
Object putVariable(String name, Object value)
Set the value of a variable.- Parameters:
name
- name of the variable.value
- value of the variable. Usenull
to delete variable.- Returns:
- previous value of the variable, or
null
.
-
getCommandLine
String getCommandLine()
Returns the unparsed command line which is being executed now.- Returns:
- command line, never
null
.
-
getCommandName
String getCommandName()
Returns the name of the command being executed.- Returns:
- command name, never
null
.
-
getRawCommandArguments
Map<String,Object> getRawCommandArguments()
Returns the raw (unprocessed) arguments of the command being executed. The types of them may differ from what the command method received.- Returns:
- map of raw (unprocessed) arguments of the command being executed, never
null
. Keys are the command line keys of the arguments, values are the raw (unprocessed) values. For keyless (positional) argument (if any), the empty string is used for the key.
-
-