Skip to content

WindowsRemovePathCommand

Base classes

Name Children Inherits
RemovePathCommand
anyenv.os_commands.base
Base class for remove path commands.

⋔ Inheritance diagram

graph TD
  3996918311["remove_path.WindowsRemovePathCommand"]
  691014020["base.RemovePathCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  691014020 --> 3996918311
  925645236 --> 691014020
  2751680898 --> 925645236

🛈 DocStrings

Bases: RemovePathCommand

Windows remove path command implementation.

Source code in src/anyenv/os_commands/remove_path.py
class WindowsRemovePathCommand(RemovePathCommand):
    """Windows remove path command implementation."""

    def create_command(self, path: str, recursive: bool = False) -> str:
        """Generate Windows removal command.

        Args:
            path: Path to remove
            recursive: Whether to remove directories recursively

        Returns:
            The removal command string
        """
        literal = ps_literal(path)
        if recursive:
            return powershell(f"Remove-Item -LiteralPath {literal} -Recurse -Force")
        # Like `rm` without -r: directories are refused.
        return powershell(
            f"if (Test-Path -LiteralPath {literal} -PathType Container) {{ exit 1 }}; "
            f"Remove-Item -LiteralPath {literal} -Force"
        )

    def parse_command(
        self,
        output: str,
        exit_code: int = 0,
    ) -> bool:
        """Parse Windows removal result.

        Args:
            output: Raw command output (ignored)
            exit_code: Command exit code

        Returns:
            True if path was removed successfully, False otherwise
        """
        return exit_code == 0

create_command

create_command(path: str, recursive: bool = False) -> str

Generate Windows removal command.

Parameters:

Name Type Description Default
path str

Path to remove

required
recursive bool

Whether to remove directories recursively

False

Returns:

Type Description
str

The removal command string

Source code in src/anyenv/os_commands/remove_path.py
def create_command(self, path: str, recursive: bool = False) -> str:
    """Generate Windows removal command.

    Args:
        path: Path to remove
        recursive: Whether to remove directories recursively

    Returns:
        The removal command string
    """
    literal = ps_literal(path)
    if recursive:
        return powershell(f"Remove-Item -LiteralPath {literal} -Recurse -Force")
    # Like `rm` without -r: directories are refused.
    return powershell(
        f"if (Test-Path -LiteralPath {literal} -PathType Container) {{ exit 1 }}; "
        f"Remove-Item -LiteralPath {literal} -Force"
    )

parse_command

parse_command(output: str, exit_code: int = 0) -> bool

Parse Windows removal result.

Parameters:

Name Type Description Default
output str

Raw command output (ignored)

required
exit_code int

Command exit code

0

Returns:

Type Description
bool

True if path was removed successfully, False otherwise

Source code in src/anyenv/os_commands/remove_path.py
def parse_command(
    self,
    output: str,
    exit_code: int = 0,
) -> bool:
    """Parse Windows removal result.

    Args:
        output: Raw command output (ignored)
        exit_code: Command exit code

    Returns:
        True if path was removed successfully, False otherwise
    """
    return exit_code == 0

:fa-brands-github: Show source on GitHub