Skip to content

is_directory

Class info

Classes

Name Children Inherits
MacOSIsDirectoryCommand
anyenv.os_commands.is_directory
macOS is directory command implementation.
    UnixIsDirectoryCommand
    anyenv.os_commands.is_directory
    Unix/Linux is directory command implementation.
      WindowsIsDirectoryCommand
      anyenv.os_commands.is_directory
      Windows is directory command implementation.

        🛈 DocStrings

        Is directory command implementations for different operating systems.

        MacOSIsDirectoryCommand

        Bases: IsDirectoryCommand

        macOS is directory command implementation.

        Source code in src/anyenv/os_commands/is_directory.py
        class MacOSIsDirectoryCommand(IsDirectoryCommand):
            """macOS is directory command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate test -d command (same as Unix).
        
                Args:
                    path: Path to test if it's a directory
        
                Returns:
                    The test command string
                """
                return f"test -d {sh_path(path)}"
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse test -d result based on exit code (same as Unix).
        
                Args:
                    output: Raw command output (ignored)
                    exit_code: Command exit code
        
                Returns:
                    True if path is a directory, False otherwise
                """
                return exit_code == 0
        

        create_command

        create_command(path: str) -> str
        

        Generate test -d command (same as Unix).

        Parameters:

        Name Type Description Default
        path str

        Path to test if it's a directory

        required

        Returns:

        Type Description
        str

        The test command string

        Source code in src/anyenv/os_commands/is_directory.py
        def create_command(self, path: str) -> str:
            """Generate test -d command (same as Unix).
        
            Args:
                path: Path to test if it's a directory
        
            Returns:
                The test command string
            """
            return f"test -d {sh_path(path)}"
        

        parse_command

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

        Parse test -d 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 is a directory, False otherwise

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

        UnixIsDirectoryCommand

        Bases: IsDirectoryCommand

        Unix/Linux is directory command implementation.

        Source code in src/anyenv/os_commands/is_directory.py
        class UnixIsDirectoryCommand(IsDirectoryCommand):
            """Unix/Linux is directory command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate Unix test -d command.
        
                Args:
                    path: Path to test if it's a directory
        
                Returns:
                    The test command string
                """
                return f"test -d {sh_path(path)}"
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse Unix test -d result based on exit code.
        
                Args:
                    output: Raw command output (ignored)
                    exit_code: Command exit code
        
                Returns:
                    True if path is a directory, False otherwise
                """
                return exit_code == 0
        

        create_command

        create_command(path: str) -> str
        

        Generate Unix test -d command.

        Parameters:

        Name Type Description Default
        path str

        Path to test if it's a directory

        required

        Returns:

        Type Description
        str

        The test command string

        Source code in src/anyenv/os_commands/is_directory.py
        def create_command(self, path: str) -> str:
            """Generate Unix test -d command.
        
            Args:
                path: Path to test if it's a directory
        
            Returns:
                The test command string
            """
            return f"test -d {sh_path(path)}"
        

        parse_command

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

        Parse Unix test -d 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 is a directory, False otherwise

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

        WindowsIsDirectoryCommand

        Bases: IsDirectoryCommand

        Windows is directory command implementation.

        Source code in src/anyenv/os_commands/is_directory.py
        class WindowsIsDirectoryCommand(IsDirectoryCommand):
            """Windows is directory command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate PowerShell directory test command.
        
                Args:
                    path: Path to test if it's a directory
        
                Returns:
                    The PowerShell command string
                """
                return powershell(
                    f"(Get-Item -LiteralPath {ps_literal(path)} -ErrorAction SilentlyContinue)"
                    ".PSIsContainer"
                )
        
            def parse_command(
                self,
                output: str,
                exit_code: int = 0,
            ) -> bool:
                """Parse PowerShell directory test result.
        
                Args:
                    output: Raw PowerShell command output
                    exit_code: Command exit code (ignored)
        
                Returns:
                    True if path is a directory, False otherwise
                """
                return output.strip().lower() == "true"
        

        create_command

        create_command(path: str) -> str
        

        Generate PowerShell directory test command.

        Parameters:

        Name Type Description Default
        path str

        Path to test if it's a directory

        required

        Returns:

        Type Description
        str

        The PowerShell command string

        Source code in src/anyenv/os_commands/is_directory.py
        def create_command(self, path: str) -> str:
            """Generate PowerShell directory test command.
        
            Args:
                path: Path to test if it's a directory
        
            Returns:
                The PowerShell command string
            """
            return powershell(
                f"(Get-Item -LiteralPath {ps_literal(path)} -ErrorAction SilentlyContinue)"
                ".PSIsContainer"
            )
        

        parse_command

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

        Parse PowerShell directory test 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 is a directory, False otherwise

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