Skip to content

remove_path

Class info

Classes

Name Children Inherits
MacOSRemovePathCommand
anyenv.os_commands.remove_path
macOS remove path command implementation.
    UnixRemovePathCommand
    anyenv.os_commands.remove_path
    Unix/Linux remove path command implementation.
      WindowsRemovePathCommand
      anyenv.os_commands.remove_path
      Windows remove path command implementation.

        🛈 DocStrings

        Remove path command implementations for different operating systems.

        MacOSRemovePathCommand

        Bases: RemovePathCommand

        macOS remove path command implementation.

        Source code in src/anyenv/os_commands/remove_path.py
        class MacOSRemovePathCommand(RemovePathCommand):
            """macOS remove path command implementation."""
        
            def create_command(self, path: str, recursive: bool = False) -> str:
                """Generate rm command (same as Unix).
        
                Args:
                    path: Path to remove
                    recursive: Whether to remove directories recursively
        
                Returns:
                    The rm command string
                """
                return f"rm -rf {sh_path(path)}" if recursive else f"rm {sh_path(path)}"
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse rm result based on exit code (same as Unix).
        
                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 rm command (same as Unix).

        Parameters:

        Name Type Description Default
        path str

        Path to remove

        required
        recursive bool

        Whether to remove directories recursively

        False

        Returns:

        Type Description
        str

        The rm command string

        Source code in src/anyenv/os_commands/remove_path.py
        def create_command(self, path: str, recursive: bool = False) -> str:
            """Generate rm command (same as Unix).
        
            Args:
                path: Path to remove
                recursive: Whether to remove directories recursively
        
            Returns:
                The rm command string
            """
            return f"rm -rf {sh_path(path)}" if recursive else f"rm {sh_path(path)}"
        

        parse_command

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

        Parse rm result based on exit code (same as Unix).

        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 rm result based on exit code (same as Unix).
        
            Args:
                output: Raw command output (ignored)
                exit_code: Command exit code
        
            Returns:
                True if path was removed successfully, False otherwise
            """
            return exit_code == 0
        

        UnixRemovePathCommand

        Bases: RemovePathCommand

        Unix/Linux remove path command implementation.

        Source code in src/anyenv/os_commands/remove_path.py
        class UnixRemovePathCommand(RemovePathCommand):
            """Unix/Linux remove path command implementation."""
        
            def create_command(self, path: str, recursive: bool = False) -> str:
                """Generate Unix rm command.
        
                Args:
                    path: Path to remove
                    recursive: Whether to remove directories recursively
        
                Returns:
                    The rm command string
                """
                return f"rm -rf {sh_path(path)}" if recursive else f"rm {sh_path(path)}"
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse Unix rm result based on exit code.
        
                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 Unix rm 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 rm command string

        Source code in src/anyenv/os_commands/remove_path.py
        def create_command(self, path: str, recursive: bool = False) -> str:
            """Generate Unix rm command.
        
            Args:
                path: Path to remove
                recursive: Whether to remove directories recursively
        
            Returns:
                The rm command string
            """
            return f"rm -rf {sh_path(path)}" if recursive else f"rm {sh_path(path)}"
        

        parse_command

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

        Parse Unix rm result based on exit code.

        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 Unix rm result based on exit code.
        
            Args:
                output: Raw command output (ignored)
                exit_code: Command exit code
        
            Returns:
                True if path was removed successfully, False otherwise
            """
            return exit_code == 0
        

        WindowsRemovePathCommand

        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