Skip to content

shell_command

ShellCommand

Bases: BaseModel

Representation of a shell command.

Attributes:

Name Type Description
prog str

...

options dict[str, str | list[str] | bool]

...

positional list[str]

...

Source code in m/ci/docker/shell_command.py
class ShellCommand(BaseModel):
    """Representation of a shell command."""

    # Name of the program to run. May contain spaces if the program is a subcommand.
    prog: str

    # Arguments to pass to the program.
    # If the key starts with `--` it will be passed as is. Otherwise it will be
    # considered as a python property and will be passed as `--key`.
    options: dict[str, str | list[str] | bool] = {}

    # Positional arguments to pass to the program.
    positional: list[str] = []

    def __str__(self) -> str:
        """Render the command as a string.

        A new line is not added to the end of the string in case the command
        needs to be piped to another command.

        Returns:
            A string representation of the command.
        """
        lines = [self.prog, *_to_list(self.options), *self.positional]
        # We need to join with a backslash and a new line.
        return' \\\n  '.join(lines)  # noqa: WPS342

__str__()

Render the command as a string.

A new line is not added to the end of the string in case the command needs to be piped to another command.

Returns:

Type Description
str

A string representation of the command.

Source code in m/ci/docker/shell_command.py
def __str__(self) -> str:
    """Render the command as a string.

    A new line is not added to the end of the string in case the command
    needs to be piped to another command.

    Returns:
        A string representation of the command.
    """
    lines = [self.prog, *_to_list(self.options), *self.positional]
    # We need to join with a backslash and a new line.
    return' \\\n  '.join(lines)  # noqa: WPS342