Class TerminalActions
java.lang.Object
com.shaft.cli.TerminalActions
Executes shell commands on local or remote terminals.
Supports local OS command execution via ProcessBuilder and
remote command execution over SSH using JSch. Commands can be run
synchronously or asynchronously with configurable timeouts.
Usage example:
SHAFT.CLI.terminal().performTerminalCommand("ls -la");
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionThis constructor is used for local terminal actions.TerminalActions(boolean asynchronous) This constructor is used for local terminal actions.TerminalActions(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName, String sshKeyFileName) This constructor is used for remote terminal actions.TerminalActions(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName, String sshKeyFileName, String dockerName, String dockerUsername) This constructor is used for remote terminal actions inside a docker.TerminalActions(String dockerName, String dockerUsername) This constructor is used for local terminal actions inside a docker. -
Method Summary
Modifier and TypeMethodDescriptionexecuteTerminalCommand(String command) Executes a terminal command and returns this terminal actions instance for fluent chaining.static TerminalActionsstatic TerminalActionsgetInstance(boolean asynchronous) static TerminalActionsgetInstance(boolean asynchronous, boolean verbose) static TerminalActionsgetInstance(boolean asynchronous, boolean verbose, boolean isInternal) static TerminalActionsgetRemoteInstance(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName, String sshKeyFileName) Creates a remote terminal actions instance that reuses the same SSH session for multiple command executions untilquit()is called.booleanbooleanperformTerminalCommand(String command) performTerminalCommands(List<String> commands) voidquit()Disconnects any reusable SSH session owned by this terminal actions instance.
-
Constructor Details
-
TerminalActions
public TerminalActions()This constructor is used for local terminal actions. -
TerminalActions
public TerminalActions(boolean asynchronous) This constructor is used for local terminal actions.- Parameters:
asynchronous- true for asynchronous execution of commands in a separate thread
-
TerminalActions
This constructor is used for local terminal actions inside a docker.- Parameters:
dockerName- the name of the docker instance that you want to execute the terminal command insidedockerUsername- the username which will be used to access the docker instance. Must have the access/privilege to execute the terminal command
-
TerminalActions
public TerminalActions(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName, String sshKeyFileName) This constructor is used for remote terminal actions.- Parameters:
sshHostName- the IP address or host name for the remote machine you want to execute the terminal command on.sshPortNumber- the port that's used for the SSH service on the target machine. Default is 22.sshUsername- the username which will be used to access the target machine via ssh. Must have the access/privilege to execute the terminal commandsshKeyFileFolderName- the directory that holds the ssh key file (usually it's somewhere in the test data of the current project)sshKeyFileName- the name of the ssh key file
-
TerminalActions
public TerminalActions(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName, String sshKeyFileName, String dockerName, String dockerUsername) This constructor is used for remote terminal actions inside a docker.- Parameters:
sshHostName- the IP address or host name for the remote machine you want to execute the terminal command on.sshPortNumber- the port that's used for the SSH service on the target machine. Default is 22.sshUsername- the username which will be used to access the target machine via ssh. Must have the access/privilege to execute the terminal commandsshKeyFileFolderName- the directory that holds the ssh key file (usually it's somewhere in the test data of the current project)sshKeyFileName- the name of the ssh key filedockerName- the name of the docker instance that you want to execute the terminal command insidedockerUsername- the username which will be used to access the docker instance. Must have the access/privilege to execute the terminal command
-
-
Method Details
-
getInstance
-
getInstance
-
getInstance
-
getInstance
public static TerminalActions getInstance(boolean asynchronous, boolean verbose, boolean isInternal) -
getRemoteInstance
public static TerminalActions getRemoteInstance(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName, String sshKeyFileName) Creates a remote terminal actions instance that reuses the same SSH session for multiple command executions untilquit()is called.- Parameters:
sshHostName- the IP address or host name for the remote machinesshPortNumber- the SSH service port on the target machinesshUsername- the username used to access the target machinesshKeyFileFolderName- the directory that holds the SSH key filesshKeyFileName- the SSH key file name- Returns:
- a reusable remote
TerminalActionsinstance
-
isRemoteTerminal
public boolean isRemoteTerminal() -
isDockerizedTerminal
public boolean isDockerizedTerminal() -
performTerminalCommands
-
performTerminalCommand
-
executeTerminalCommand
Executes a terminal command and returns this terminal actions instance for fluent chaining.- Parameters:
command- the command to execute- Returns:
- this
TerminalActionsinstance
-
quit
public void quit()Disconnects any reusable SSH session owned by this terminal actions instance.This method is safe to call before the first remote command is executed and is a no-op for local terminals or ephemeral remote terminals.
-