Command
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| BaseCommand slashed.base Abstract base class for commands. |
||
| Generic typing Abstract base class for generic types. |
⋔ Inheritance diagram¶
graph TD
1376813048["base.Command"]
900363605["base.BaseCommand"]
925645236["abc.ABC"]
2751680898["builtins.object"]
3481597255["typing.Generic"]
900363605 --> 1376813048
925645236 --> 900363605
2751680898 --> 925645236
3481597255 --> 1376813048
2751680898 --> 3481597255
🛈 DocStrings¶
Bases: BaseCommand
Concrete command that can be created directly.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
TContext
|
Type of the context data. Defaults to Any for flexibility. Use explicit type parameter for type-safe commands. |
Any
|
Example
Source code in src/slashed/base.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
__init__
¶
__init__(
execute_func: CommandFunc,
*,
name: str | None = None,
description: str | None = None,
category: str = "general",
usage: str | None = None,
help_text: str | None = None,
completer: CompletionProvider | Callable[[], CompletionProvider] | None = None,
condition: ConditionPredicate | None = None,
visible: VisibilityPredicate[TContext] | None = None,
) -> None
Initialize command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execute_func
|
CommandFunc
|
Function to execute command |
required |
name
|
str | None
|
Optional command name (defaults to function name) |
None
|
description
|
str | None
|
Command description (defaults to function docstring) |
None
|
category
|
str
|
Command category |
'general'
|
usage
|
str | None
|
Optional usage string (auto-generated if None) |
None
|
help_text
|
str | None
|
Optional help text (defaults to description) |
None
|
completer
|
CompletionProvider | Callable[[], CompletionProvider] | None
|
Optional completion provider or factory |
None
|
condition
|
ConditionPredicate | None
|
Optional predicate to check command availability |
None
|
visible
|
VisibilityPredicate[TContext] | None
|
Optional predicate to check command visibility in listings |
None
|
Source code in src/slashed/base.py
execute
async
¶
execute(
ctx: CommandContext[TContext],
args: list[str] | None = None,
kwargs: dict[str, str] | None = None,
) -> Any
Execute the command using provided function.
Source code in src/slashed/base.py
from_raw
classmethod
¶
from_raw(
func: Callable[[CommandContext[Any], list[str], dict[str, str]], Any | Awaitable[Any]],
*,
name: str | None = None,
description: str | None = None,
category: str = "general",
usage: str | None = None,
help_text: str | None = None,
completer: CompletionProvider | Callable[[], CompletionProvider] | None = None,
condition: ConditionPredicate | None = None,
visible: VisibilityPredicate[Any] | None = None,
) -> Command[Any]
Create a command from a raw-style function.
Use this for functions that expect the traditional (ctx, args, kwargs) signature, such as when wrapping external command sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[CommandContext[Any], list[str], dict[str, str]], Any | Awaitable[Any]]
|
Function with signature (ctx, args: list[str], kwargs: dict[str, str]) |
required |
name
|
str | None
|
Optional command name (defaults to function name) |
None
|
description
|
str | None
|
Command description (defaults to function docstring) |
None
|
category
|
str
|
Command category |
'general'
|
usage
|
str | None
|
Optional usage string |
None
|
help_text
|
str | None
|
Optional help text |
None
|
completer
|
CompletionProvider | Callable[[], CompletionProvider] | None
|
Optional completion provider or factory |
None
|
condition
|
ConditionPredicate | None
|
Optional predicate to check command availability |
None
|
visible
|
VisibilityPredicate[Any] | None
|
Optional predicate to check command visibility |
None
|
Example
Source code in src/slashed/base.py
get_callable
¶
get_completer
¶
get_completer() -> CompletionProvider | None
Get completion provider.
Source code in src/slashed/base.py
is_available
¶
is_visible
¶
is_visible(ctx: CommandContext[TContext]) -> bool
Check if command should be visible based on visibility predicate.