Skip to content

ArgumentValidatingCommand

Nicolas Couture edited this page Apr 19, 2026 · 1 revision

ArgumentValidatingCommand

ArgumentValidatingCommand is used for commands that require a specific set of arguments to execute successfully.

Usage

It compares the provided arguments against a required list and triggers different callbacks based on the result.

import MockSSH

def save_config(instance):
    instance.writeln("Configuration saved successfully.")

def show_usage(instance):
    instance.writeln("Usage: commit force")

# This command will only succeed if the user types 'commit force'
commit_cmd = MockSSH.ArgumentValidatingCommand(
    "commit",            # Base command name
    [save_config],       # Success callbacks
    [show_usage],        # Failure callbacks
    "force"              # Required arguments
)

Parameters

  • name: The trigger command string.
  • success_callbacks: A list of functions called if arguments match.
  • failure_callbacks: A list of functions called if arguments do not match.
  • *args: One or more strings representing the exact expected arguments.

Clone this wiki locally