Skip to content

BaseCommand

Sub classes

Name Children Inherits
Command
slashed.base
Concrete command that can be created directly.
    SlashedCommand
    slashed.commands
    Base class for declarative commands.

    Base classes

    Name Children Inherits
    ABC
    abc
    Helper class that provides a standard way to create an ABC using

    ⋔ Inheritance diagram

    graph TD
      900363605["base.BaseCommand"]
      925645236["abc.ABC"]
      2751680898["builtins.object"]
      925645236 --> 900363605
      2751680898 --> 925645236

    🛈 DocStrings

    Bases: ABC

    Abstract base class for commands.

    Source code in src/slashed/base.py
    class BaseCommand(ABC):
        """Abstract base class for commands."""
    
        name: str
        """Command name"""
    
        description: str
        """Command description"""
    
        category: str
        """Command category"""
    
        usage: str | None
        """Command usage"""
    
        _help_text: str | None
        """Optional help text"""
    
        raw_args: bool = False
        """Pass the words after the command name unparsed, as positional arguments.
    
        For commands forwarding an argv (``/exec git -C dir status``): no ``--flag value``
        parsing and no ``--help`` interception.
        """
    
        def get_callable(self) -> Callable[..., Any]:
            """The callable whose signature defines the command's parameters."""
            return self.execute
    
        def is_available(self) -> bool:
            """Check if command is currently available.
    
            Override or use condition predicate to implement dynamic availability.
            """
            return True
    
        def is_visible(self, ctx: CommandContext[Any]) -> bool:
            """Check if command should be visible in command listings.
    
            Override to implement context-dependent visibility. This is called
            when listing commands to filter which ones should be shown to the user.
    
            Args:
                ctx: The command context, providing access to context data
    
            Returns:
                True if command should be listed, False to hide it
            """
            return True
    
        def get_completer(self) -> CompletionProvider | None:
            """Get completion provider for this command if supported."""
            return None
    
        def format_usage(self) -> str | None:
            """Format usage string."""
            if not self.usage:
                return None
            return f"Usage: /{self.name} {self.usage}"
    
        @property
        def help_text(self) -> str:
            """Get help text, falling back to description if not set."""
            return self._help_text or self.description
    
        @abstractmethod
        async def execute(
            self, ctx: CommandContext[Any], args: list[str], kwargs: dict[str, str]
        ) -> Any:
            """Execute the command with parsed arguments."""
            ...
    

    category instance-attribute

    category: str
    

    Command category

    description instance-attribute

    description: str
    

    Command description

    help_text property

    help_text: str
    

    Get help text, falling back to description if not set.

    name instance-attribute

    name: str
    

    Command name

    raw_args class-attribute instance-attribute

    raw_args: bool = False
    

    Pass the words after the command name unparsed, as positional arguments.

    For commands forwarding an argv (/exec git -C dir status): no --flag value parsing and no --help interception.

    usage instance-attribute

    usage: str | None
    

    Command usage

    execute abstractmethod async

    execute(ctx: CommandContext[Any], args: list[str], kwargs: dict[str, str]) -> Any
    

    Execute the command with parsed arguments.

    Source code in src/slashed/base.py
    @abstractmethod
    async def execute(
        self, ctx: CommandContext[Any], args: list[str], kwargs: dict[str, str]
    ) -> Any:
        """Execute the command with parsed arguments."""
        ...
    

    format_usage

    format_usage() -> str | None
    

    Format usage string.

    Source code in src/slashed/base.py
    def format_usage(self) -> str | None:
        """Format usage string."""
        if not self.usage:
            return None
        return f"Usage: /{self.name} {self.usage}"
    

    get_callable

    get_callable() -> Callable[..., Any]
    

    The callable whose signature defines the command's parameters.

    Source code in src/slashed/base.py
    def get_callable(self) -> Callable[..., Any]:
        """The callable whose signature defines the command's parameters."""
        return self.execute
    

    get_completer

    get_completer() -> CompletionProvider | None
    

    Get completion provider for this command if supported.

    Source code in src/slashed/base.py
    def get_completer(self) -> CompletionProvider | None:
        """Get completion provider for this command if supported."""
        return None
    

    is_available

    is_available() -> bool
    

    Check if command is currently available.

    Override or use condition predicate to implement dynamic availability.

    Source code in src/slashed/base.py
    def is_available(self) -> bool:
        """Check if command is currently available.
    
        Override or use condition predicate to implement dynamic availability.
        """
        return True
    

    is_visible

    is_visible(ctx: CommandContext[Any]) -> bool
    

    Check if command should be visible in command listings.

    Override to implement context-dependent visibility. This is called when listing commands to filter which ones should be shown to the user.

    Parameters:

    Name Type Description Default
    ctx CommandContext[Any]

    The command context, providing access to context data

    required

    Returns:

    Type Description
    bool

    True if command should be listed, False to hide it

    Source code in src/slashed/base.py
    def is_visible(self, ctx: CommandContext[Any]) -> bool:
        """Check if command should be visible in command listings.
    
        Override to implement context-dependent visibility. This is called
        when listing commands to filter which ones should be shown to the user.
    
        Args:
            ctx: The command context, providing access to context data
    
        Returns:
            True if command should be listed, False to hide it
        """
        return True
    

    :fa-brands-github: Show source on GitHub