You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/developing/command.rst
+11-18Lines changed: 11 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@
4
4
Adding a New Command
5
5
======================
6
6
7
-
AttackMate supports extending its functionality by adding new commands.
7
+
AttackMate supports extending its functionality by adding new commands.
8
8
This section details the steps required to integrate a new command.
9
9
10
10
11
11
1. Define the Command Schema
12
12
=============================
13
13
14
-
All Commands in AttackMate inherit from ``BaseCommand``.
14
+
All Commands in AttackMate inherit from ``BaseCommand``.
15
15
To create a new command, define a class in `/src/attackmate/schemas` and register it using the ``@CommandRegistry.register('<command_type>')`` decorator.
16
16
17
17
For example, to add a ``debug`` command:
@@ -21,7 +21,7 @@ For example, to add a ``debug`` command:
21
21
from typing import Literal
22
22
from .base import BaseCommand
23
23
from attackmate.command import CommandRegistry
24
-
24
+
25
25
@CommandRegistry.register('debug')
26
26
class DebugCommand(BaseCommand):
27
27
type: Literal['debug']
@@ -30,7 +30,7 @@ For example, to add a ``debug`` command:
30
30
wait_for_key: bool = False
31
31
cmd: str = ''
32
32
33
-
Registering the command in the ``CommandRegistry`` allows the command to be also instantiated dynamically using the ``Command.create()`` method and is essential to
33
+
Registering the command in the ``CommandRegistry`` allows the command to be also instantiated dynamically using the ``Command.create()`` method and is essential to
34
34
make them usable in external python scripts.
35
35
36
36
@@ -53,16 +53,16 @@ The new command should be handled by an executor in `src/attackmate/executors``
53
53
54
54
3. Ensure the Executor Handles the New Command
55
55
==============================================
56
-
57
-
The ``ExecutorFactory`` class manages and creates executor instances based on command types.
56
+
57
+
The ``ExecutorFactory`` class manages and creates executor instances based on command types.
58
58
It maintains a registry (``_executors``) that maps command type strings to executor classes, allowing for dynamic execution of different command types.
59
-
Executors are registered using the ``register_executor`` method, which provides a decorator to associate a command type with a class.
59
+
Executors are registered using the ``register_executor`` method, which provides a decorator to associate a command type with a class.
60
60
When a command is executed, the ``create_executor`` method retrieves the corresponding executor class, filters the constructor arguments based on the class's signature, and then creates an instance.
61
61
62
-
Accordingly, executors must be registered using the ``@executor_factory.register_executor('<command_type>')`` decorator.
62
+
Accordingly, executors must be registered using the ``@executor_factory.register_executor('<command_type>')`` decorator.
63
63
64
-
If the new executor class requires additional initialization arguments, these must be added to the ``_get_executor_config`` method in ``attackmate.py``.
65
-
All configurations are always passed to the ``ExecutorFactory``.
64
+
If the new executor class requires additional initialization arguments, these must be added to the ``_get_executor_config`` method in ``attackmate.py``.
65
+
All configurations are always passed to the ``ExecutorFactory``.
66
66
The factory filters the provided configurations based on the class constructor signature, ensuring that only the required parameters are used.
67
67
68
68
::
@@ -93,7 +93,7 @@ Update the ``LoopCommand`` schema to include the new command.
0 commit comments