Skip to content

exists

Class info

Classes

Name Children Inherits
MacOSExistsCommand
anyenv.os_commands.exists
macOS exists command implementation.
    UnixExistsCommand
    anyenv.os_commands.exists
    Unix/Linux exists command implementation.
      WindowsExistsCommand
      anyenv.os_commands.exists
      Windows exists command implementation.

        🛈 DocStrings

        Exists command implementations for different operating systems.

        MacOSExistsCommand

        Bases: ExistsCommand

        macOS exists command implementation.

        Source code in src/anyenv/os_commands/exists.py
        class MacOSExistsCommand(ExistsCommand):
            """macOS exists command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate test -e command (same as Unix).
        
                Args:
                    path: Path to test for existence
        
                Returns:
                    The test command string
                """
                return f"test -e {sh_path(path)}"
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse test result based on exit code (same as Unix).
        
                Args:
                    output: Raw command output (ignored)
                    exit_code: Command exit code
        
                Returns:
                    True if path exists, False otherwise
                """
                return exit_code == 0
        

        create_command

        create_command(path: str) -> str
        

        Generate test -e command (same as Unix).

        Parameters:

        Name Type Description Default
        path str

        Path to test for existence

        required

        Returns:

        Type Description
        str

        The test command string

        Source code in src/anyenv/os_commands/exists.py
        def create_command(self, path: str) -> str:
            """Generate test -e command (same as Unix).
        
            Args:
                path: Path to test for existence
        
            Returns:
                The test command string
            """
            return f"test -e {sh_path(path)}"
        

        parse_command

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

        Parse test 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 exists, False otherwise

        Source code in src/anyenv/os_commands/exists.py
        def parse_command(
            self,
            output: str,
            exit_code: int = 0,
        ) -> bool:
            """Parse test result based on exit code (same as Unix).
        
            Args:
                output: Raw command output (ignored)
                exit_code: Command exit code
        
            Returns:
                True if path exists, False otherwise
            """
            return exit_code == 0
        

        UnixExistsCommand

        Bases: ExistsCommand

        Unix/Linux exists command implementation.

        Source code in src/anyenv/os_commands/exists.py
        class UnixExistsCommand(ExistsCommand):
            """Unix/Linux exists command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate Unix test -e command.
        
                Args:
                    path: Path to test for existence
        
                Returns:
                    The test command string
                """
                return f"test -e {sh_path(path)}"
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse Unix test result based on exit code.
        
                Args:
                    output: Raw command output (ignored)
                    exit_code: Command exit code
        
                Returns:
                    True if path exists, False otherwise
                """
                return exit_code == 0
        

        create_command

        create_command(path: str) -> str
        

        Generate Unix test -e command.

        Parameters:

        Name Type Description Default
        path str

        Path to test for existence

        required

        Returns:

        Type Description
        str

        The test command string

        Source code in src/anyenv/os_commands/exists.py
        def create_command(self, path: str) -> str:
            """Generate Unix test -e command.
        
            Args:
                path: Path to test for existence
        
            Returns:
                The test command string
            """
            return f"test -e {sh_path(path)}"
        

        parse_command

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

        Parse Unix test 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 exists, False otherwise

        Source code in src/anyenv/os_commands/exists.py
        def parse_command(
            self,
            output: str,
            exit_code: int = 0,
        ) -> bool:
            """Parse Unix test result based on exit code.
        
            Args:
                output: Raw command output (ignored)
                exit_code: Command exit code
        
            Returns:
                True if path exists, False otherwise
            """
            return exit_code == 0
        

        WindowsExistsCommand

        Bases: ExistsCommand

        Windows exists command implementation.

        Source code in src/anyenv/os_commands/exists.py
        class WindowsExistsCommand(ExistsCommand):
            """Windows exists command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate PowerShell Test-Path command.
        
                Args:
                    path: Path to test for existence
        
                Returns:
                    The PowerShell command string
                """
                return powershell(f"Test-Path -LiteralPath {ps_literal(path)}")
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse PowerShell Test-Path result.
        
                Args:
                    output: Raw PowerShell command output
                    exit_code: Command exit code (ignored)
        
                Returns:
                    True if path exists, False otherwise
                """
                return output.strip().lower() == "true"
        

        create_command

        create_command(path: str) -> str
        

        Generate PowerShell Test-Path command.

        Parameters:

        Name Type Description Default
        path str

        Path to test for existence

        required

        Returns:

        Type Description
        str

        The PowerShell command string

        Source code in src/anyenv/os_commands/exists.py
        def create_command(self, path: str) -> str:
            """Generate PowerShell Test-Path command.
        
            Args:
                path: Path to test for existence
        
            Returns:
                The PowerShell command string
            """
            return powershell(f"Test-Path -LiteralPath {ps_literal(path)}")
        

        parse_command

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

        Parse PowerShell Test-Path result.

        Parameters:

        Name Type Description Default
        output str

        Raw PowerShell command output

        required
        exit_code int

        Command exit code (ignored)

        0

        Returns:

        Type Description
        bool

        True if path exists, False otherwise

        Source code in src/anyenv/os_commands/exists.py
        def parse_command(
            self,
            output: str,
            exit_code: int = 0,
        ) -> bool:
            """Parse PowerShell Test-Path result.
        
            Args:
                output: Raw PowerShell command output
                exit_code: Command exit code (ignored)
        
            Returns:
                True if path exists, False otherwise
            """
            return output.strip().lower() == "true"