Skip to content

which

Class info

Classes

Name Children Inherits
MacOSWhichCommand
anyenv.os_commands.which
macOS which command implementation.
    UnixWhichCommand
    anyenv.os_commands.which
    Unix/Linux which command implementation.
      WindowsWhichCommand
      anyenv.os_commands.which
      Windows where command implementation.

        🛈 DocStrings

        Which command implementations for different operating systems.

        MacOSWhichCommand

        Bases: WhichCommand

        macOS which command implementation.

        Source code in src/anyenv/os_commands/which.py
        class MacOSWhichCommand(WhichCommand):
            """macOS which command implementation."""
        
            def create_command(self, executable: str) -> str:
                """Generate which command (same as Unix).
        
                Args:
                    executable: Name of executable to find
        
                Returns:
                    The which command string
                """
                return f"which {sh_quote(executable)}"
        
            def parse_command(self, output: str, exit_code: int = 0) -> str | None:
                """Parse which result (same as Unix).
        
                Args:
                    output: Raw command output
                    exit_code: Command exit code
        
                Returns:
                    Path to executable or None if not found
                """
                if exit_code != 0:
                    return None
                path = output.strip()
                return path if path else None
        

        create_command

        create_command(executable: str) -> str
        

        Generate which command (same as Unix).

        Parameters:

        Name Type Description Default
        executable str

        Name of executable to find

        required

        Returns:

        Type Description
        str

        The which command string

        Source code in src/anyenv/os_commands/which.py
        def create_command(self, executable: str) -> str:
            """Generate which command (same as Unix).
        
            Args:
                executable: Name of executable to find
        
            Returns:
                The which command string
            """
            return f"which {sh_quote(executable)}"
        

        parse_command

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

        Parse which result (same as Unix).

        Parameters:

        Name Type Description Default
        output str

        Raw command output

        required
        exit_code int

        Command exit code

        0

        Returns:

        Type Description
        str | None

        Path to executable or None if not found

        Source code in src/anyenv/os_commands/which.py
        def parse_command(self, output: str, exit_code: int = 0) -> str | None:
            """Parse which result (same as Unix).
        
            Args:
                output: Raw command output
                exit_code: Command exit code
        
            Returns:
                Path to executable or None if not found
            """
            if exit_code != 0:
                return None
            path = output.strip()
            return path if path else None
        

        UnixWhichCommand

        Bases: WhichCommand

        Unix/Linux which command implementation.

        Source code in src/anyenv/os_commands/which.py
        class UnixWhichCommand(WhichCommand):
            """Unix/Linux which command implementation."""
        
            def create_command(self, executable: str) -> str:
                """Generate Unix which command.
        
                Args:
                    executable: Name of executable to find
        
                Returns:
                    The which command string
                """
                return f"which {sh_quote(executable)}"
        
            def parse_command(self, output: str, exit_code: int = 0) -> str | None:
                """Parse Unix which result.
        
                Args:
                    output: Raw command output
                    exit_code: Command exit code
        
                Returns:
                    Path to executable or None if not found
                """
                if exit_code != 0:
                    return None
                path = output.strip()
                return path if path else None
        

        create_command

        create_command(executable: str) -> str
        

        Generate Unix which command.

        Parameters:

        Name Type Description Default
        executable str

        Name of executable to find

        required

        Returns:

        Type Description
        str

        The which command string

        Source code in src/anyenv/os_commands/which.py
        def create_command(self, executable: str) -> str:
            """Generate Unix which command.
        
            Args:
                executable: Name of executable to find
        
            Returns:
                The which command string
            """
            return f"which {sh_quote(executable)}"
        

        parse_command

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

        Parse Unix which result.

        Parameters:

        Name Type Description Default
        output str

        Raw command output

        required
        exit_code int

        Command exit code

        0

        Returns:

        Type Description
        str | None

        Path to executable or None if not found

        Source code in src/anyenv/os_commands/which.py
        def parse_command(self, output: str, exit_code: int = 0) -> str | None:
            """Parse Unix which result.
        
            Args:
                output: Raw command output
                exit_code: Command exit code
        
            Returns:
                Path to executable or None if not found
            """
            if exit_code != 0:
                return None
            path = output.strip()
            return path if path else None
        

        WindowsWhichCommand

        Bases: WhichCommand

        Windows where command implementation.

        Source code in src/anyenv/os_commands/which.py
        class WindowsWhichCommand(WhichCommand):
            """Windows where command implementation."""
        
            def create_command(self, executable: str) -> str:
                """Generate Windows where command.
        
                Args:
                    executable: Name of executable to find
        
                Returns:
                    The where command string
                """
                return powershell(f"where.exe {ps_literal(executable)}")
        
            def parse_command(self, output: str, exit_code: int = 0) -> str | None:
                """Parse Windows where result.
        
                Args:
                    output: Raw command output
                    exit_code: Command exit code
        
                Returns:
                    Path to first matching executable or None if not found
                """
                if exit_code != 0:
                    return None
                # where can return multiple paths, take the first one
                lines = output.strip().splitlines()
                return lines[0].strip() if lines else None
        

        create_command

        create_command(executable: str) -> str
        

        Generate Windows where command.

        Parameters:

        Name Type Description Default
        executable str

        Name of executable to find

        required

        Returns:

        Type Description
        str

        The where command string

        Source code in src/anyenv/os_commands/which.py
        def create_command(self, executable: str) -> str:
            """Generate Windows where command.
        
            Args:
                executable: Name of executable to find
        
            Returns:
                The where command string
            """
            return powershell(f"where.exe {ps_literal(executable)}")
        

        parse_command

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

        Parse Windows where result.

        Parameters:

        Name Type Description Default
        output str

        Raw command output

        required
        exit_code int

        Command exit code

        0

        Returns:

        Type Description
        str | None

        Path to first matching executable or None if not found

        Source code in src/anyenv/os_commands/which.py
        def parse_command(self, output: str, exit_code: int = 0) -> str | None:
            """Parse Windows where result.
        
            Args:
                output: Raw command output
                exit_code: Command exit code
        
            Returns:
                Path to first matching executable or None if not found
            """
            if exit_code != 0:
                return None
            # where can return multiple paths, take the first one
            lines = output.strip().splitlines()
            return lines[0].strip() if lines else None