Skip to content

CLIResource

Base classes

Name Children Inherits
BaseResource
llmling.config.models
Base class for all resource types.

⋔ Inheritance diagram

graph TD
  1256000812["models.CLIResource"]
  1028592330["models.BaseResource"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  1028592330 --> 1256000812
  330168112 --> 1028592330
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseResource

Resource from CLI command execution.

Source code in src/llmling/config/models.py
class CLIResource(BaseResource):
    """Resource from CLI command execution."""

    type: Literal["cli"] = Field(default="cli", init=False)
    """Discriminator field identifying this as a CLI-based resource."""

    command: str | Sequence[str]
    """Command to execute (string or sequence of arguments)."""

    shell: bool = False
    """Whether to run the command through a shell."""

    cwd: str | None = None
    """Working directory for command execution."""

    timeout: float | None = Field(None, ge=0)
    """Maximum time in seconds to wait for command completion."""

    @model_validator(mode="after")
    def validate_command(self) -> CLIResource:
        """Validate command configuration."""
        if not self.command:
            msg = "Command cannot be empty"
            raise ValueError(msg)
        if (
            isinstance(self.command, list | tuple)
            and not self.shell
            and not all(isinstance(part, str) for part in self.command)
        ):
            msg = "When shell=False, all command parts must be strings"
            raise ValueError(msg)
        return self

command instance-attribute

command: str | Sequence[str]

Command to execute (string or sequence of arguments).

cwd class-attribute instance-attribute

cwd: str | None = None

Working directory for command execution.

shell class-attribute instance-attribute

shell: bool = False

Whether to run the command through a shell.

timeout class-attribute instance-attribute

timeout: float | None = Field(None, ge=0)

Maximum time in seconds to wait for command completion.

type class-attribute instance-attribute

type: Literal['cli'] = Field(default='cli', init=False)

Discriminator field identifying this as a CLI-based resource.

validate_command

validate_command() -> CLIResource

Validate command configuration.

Source code in src/llmling/config/models.py
@model_validator(mode="after")
def validate_command(self) -> CLIResource:
    """Validate command configuration."""
    if not self.command:
        msg = "Command cannot be empty"
        raise ValueError(msg)
    if (
        isinstance(self.command, list | tuple)
        and not self.shell
        and not all(isinstance(part, str) for part in self.command)
    ):
        msg = "When shell=False, all command parts must be strings"
        raise ValueError(msg)
    return self

:fa-brands-github: Show source on GitHub