Class CliSessionImpl
- All Implemented Interfaces:
ICliSession
-
Constructor Summary
ConstructorsConstructorDescriptionCliSessionImpl(org.apache.felix.service.command.CommandSession commandSession, String commandName, Map<String, Object> rawArgs) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcriticalSection(Runnable runnable) Runs code in a critical section.<T> TcriticalSection(Callable<T> callable) Runs code in a critical section.Returns the unparsed command line which is being executed now.Returns the name of the command being executed.Returns the current namespace for this session.static StringgetCurrentNamespace(org.apache.felix.service.command.CommandSession commandSession) Returns the current namespace for the given session.Returns the current session's working directory.Returns exception of the last executed command.Returns result of the last executed command.Returns the raw (unprocessed) arguments of the command being executed.getVariable(String name) Get the value of a variable.<T> TgetVariable(String name, Class<T> clazz) Get the value of a variable casted to the given class.Returns all variable names.putVariable(String name, Object value) Set the value of a variable.Reads a line of user input from the console:voidsetCurrentNamespace(String namespace) Sets the new current namespace for this session.static voidsetCurrentNamespace(org.apache.felix.service.command.CommandSession commandSession, String namespace) Sets the current namespace for the given session.voidsetCurrentWorkDir(Path path) Sets the new current working directory for this session.
-
Constructor Details
-
CliSessionImpl
public CliSessionImpl(org.apache.felix.service.command.CommandSession commandSession, String commandName, Map<String, Object> rawArgs) Creates a new instance.- Parameters:
commandSession- command session, cannot benull.commandName- name of the command being executed, cannot benull.rawArgs- raw arguments to the command being executed, cannot benull.
-
-
Method Details
-
getCurrentNamespace
public static String getCurrentNamespace(org.apache.felix.service.command.CommandSession commandSession) Returns the current namespace for the given session.- Parameters:
commandSession- command session, cannot benull.- Returns:
- the current namespace, never
null.
-
setCurrentNamespace
public static void setCurrentNamespace(org.apache.felix.service.command.CommandSession commandSession, String namespace) Sets the current namespace for the given session.- Parameters:
commandSession- command session, cannot benull.namespace- new current namespace. Ifnullor blank, the default namespace is set.
-
criticalSection
Description copied from interface:ICliSessionRuns 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.- Specified by:
criticalSectionin interfaceICliSession- Type Parameters:
T- critical section return type.- Parameters:
callable- 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
Description copied from interface:ICliSessionRuns 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.- Specified by:
criticalSectionin interfaceICliSession- Parameters:
runnable- task to run in a critical section. It will run in the same thread.- See Also:
-
readLine
Description copied from interface:ICliSessionReads a line of user input from the console:String userName = session.readLine("Please enter your name: "); ...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 in
ICliSession.criticalSection(Callable).- Specified by:
readLinein interfaceICliSession- 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
Description copied from interface:ICliSessionGet the value of a variable.- Specified by:
getVariablein interfaceICliSession- Parameters:
name- name of the variable.- Returns:
- variable value, or
null.
-
getVariable
Description copied from interface:ICliSessionGet the value of a variable casted to the given class.- Specified by:
getVariablein interfaceICliSession- Type Parameters:
T- class to cast to.- Parameters:
name- name of the variable.clazz- class to cast to.- Returns:
- variable value, or
null.
-
getVariables
Description copied from interface:ICliSessionReturns all variable names.- Specified by:
getVariablesin interfaceICliSession- Returns:
- variable names, never
null.
-
putVariable
Description copied from interface:ICliSessionSet the value of a variable.- Specified by:
putVariablein interfaceICliSession- Parameters:
name- name of the variable.value- value of the variable. Usenullto delete variable.- Returns:
- previous value of the variable, or
null.
-
getCommandLine
Description copied from interface:ICliSessionReturns the unparsed command line which is being executed now.- Specified by:
getCommandLinein interfaceICliSession- Returns:
- command line, never
null.
-
getCommandName
Description copied from interface:ICliSessionReturns the name of the command being executed.- Specified by:
getCommandNamein interfaceICliSession- Returns:
- command name, never
null.
-
getRawCommandArguments
Description copied from interface:ICliSessionReturns the raw (unprocessed) arguments of the command being executed. The types of them may differ from what the command method received.- Specified by:
getRawCommandArgumentsin interfaceICliSession- 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.
-
getCurrentWorkDir
Description copied from interface:ICliSessionReturns the current session's working directory. You should resolve all relative paths against this directory (except for workspace relative paths).This is not the workspace directory. Initially this value is set to be the directory the 1C:EDT CLI process is executed from. But the user (or other commands) can change it later for each session separately either by calling the builtin
cdcommand, or by changing the_cwdsession variable.Because of this you should not rely on the JVM process working directory (
System.getProperty("user.dir")orFile.getAbsolutePath()or other methods like this).- Specified by:
getCurrentWorkDirin interfaceICliSession- Returns:
- the current working directory of the current session. Never
null. - See Also:
-
setCurrentWorkDir
Description copied from interface:ICliSessionSets the new current working directory for this session.Internally this is done by setting the
_cwdsession variable. SeeICliSession.getCurrentWorkDir()for the details about what the current session's working directory is and how to use it.- Specified by:
setCurrentWorkDirin interfaceICliSession- Parameters:
path- new current working dir, cannot benull. Must be absolute.- See Also:
-
getCurrentNamespace
Description copied from interface:ICliSessionReturns the current namespace for this session.- Specified by:
getCurrentNamespacein interfaceICliSession- Returns:
- the current namespace, never
null.
-
setCurrentNamespace
Description copied from interface:ICliSessionSets the new current namespace for this session.Internally this is done by setting the
SCOPEsession variable.- Specified by:
setCurrentNamespacein interfaceICliSession- Parameters:
namespace- new namespace, cannot benull.- See Also:
-
getLastCommandException
Description copied from interface:ICliSessionReturns exception of the last executed command.- Specified by:
getLastCommandExceptionin interfaceICliSession- Returns:
- exception of the last executed command, may be
null.
-
getLastCommandResult
Description copied from interface:ICliSessionReturns result of the last executed command.- Specified by:
getLastCommandResultin interfaceICliSession- Returns:
- result of the last executed command, may be
null.
-