-
Notifications
You must be signed in to change notification settings - Fork 25
PromptingCommand
Nicolas Couture edited this page Apr 19, 2026
·
1 revision
PromptingCommand is a specialized subclass of SSHCommand designed for multi-step interactions, such as password prompts or confirmation dialogs.
It uses a sequence of callbacks to transition through different states of an interaction.
import MockSSH
def on_success(instance):
instance.writeln("Access Granted.")
instance.protocol.prompt = "admin# "
def on_failure(instance):
instance.writeln("Access Denied.")
# Define the command
secret_gate = MockSSH.PromptingCommand(
name="enable",
password="supersecret",
prompt="Password: ",
success_callbacks=[on_success],
failure_callbacks=[on_failure]
)- When the user types
enable, the server displays theprompt("Password: "). - The server enters a "password mode" where input is not echoed back.
- Once the user presses Enter, the input is compared against the
password. - If it matches, all
success_callbacksare executed; otherwise,failure_callbacksrun. - The command then automatically exits.