Skip to content

UnixWhichCommand

Base classes

Name Children Inherits
WhichCommand
anyenv.os_commands.base
Base class for which/where commands to locate executables.

⋔ Inheritance diagram

graph TD
  1303925040["which.UnixWhichCommand"]
  2658962468["base.WhichCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  2658962468 --> 1303925040
  925645236 --> 2658962468
  2751680898 --> 925645236

🛈 DocStrings

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

:fa-brands-github: Show source on GitHub