SlashedCommand
Sub classes¶
| Name | Children | Inherits |
|---|---|---|
| HelpCommand slashed.builtin.help_cmd Display help information about commands. |
||
| ExitCommand slashed.builtin.help_cmd Exit the chat session. |
||
| ExecCommand slashed.builtin.system Execute a system command and capture its output. |
||
| RunCommand slashed.builtin.system Launch a system command asynchronously. |
||
| ProcessesCommand slashed.builtin.system List running processes. |
||
| SystemInfoCommand slashed.builtin.system Show system information. |
||
| KillCommand slashed.builtin.system Kill a running process. |
||
| EnvCommand slashed.builtin.system Show or set environment variables. |
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| BaseCommand slashed.base Abstract base class for commands. |
⋔ Inheritance diagram¶
graph TD
807245086["commands.SlashedCommand"]
900363605["base.BaseCommand"]
925645236["abc.ABC"]
2751680898["builtins.object"]
900363605 --> 807245086
925645236 --> 900363605
2751680898 --> 925645236
🛈 DocStrings¶
Bases: BaseCommand
Base class for declarative commands.
Allows defining commands using class syntax with explicit parameters:
Example
class AddWorkerCommand(SlashedCommand): '''Add a new worker to the pool.'''
name = "add-worker"
category = "tools"
async def execute_command(
self,
ctx: CommandContext, # Optional depending on implementation
worker_id: str, # required param (no default)
host: str, # required param (no default)
port: int = 8080, # optional param (has default)
):
await ctx.print(f"Adding worker {worker_id} at {host}:{port}")
Context-free command¶
class VersionCommand(SlashedCommand): '''Show version information.'''
name = "version"
async def execute_command(self, major: int, minor: int = 0):
return f"v{major}.{minor}"
Source code in src/slashed/commands.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
description
class-attribute
instance-attribute
¶
Optional description override
help_text
class-attribute
instance-attribute
¶
Optional help text override
__init__
¶
__init_subclass__
¶
Process command class at definition time.
Validates required attributes and generates description/usage from metadata.
Source code in src/slashed/commands.py
execute
async
¶
execute(ctx: CommandContext[Any], args: list[str], kwargs: dict[str, str]) -> Any
Execute command by binding command-line arguments to method parameters.
Source code in src/slashed/commands.py
execute_command
abstractmethod
async
¶
Execute the command logic.
This method should be implemented with explicit parameters. Parameters without default values are treated as required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Any
|
Command arguments (may include context as first param) |
()
|
kwargs
|
Any
|
Command keyword arguments |
{}
|