Skip to content

darwin_brew

DarwinBrewCaskManager

Homebrew cask manager for macOS (brew install --cask).

Source code in src/personal_os_setup/tasks/managers/darwin_brew.py
class DarwinBrewCaskManager:
    """Homebrew cask manager for macOS (`brew install --cask`)."""

    name = "cask"

    def is_installed(self, package: str) -> bool:
        brew = _ensure_brew()
        if brew is None:
            return False

        # `brew list --cask <name>` exits 0 if the cask is installed.
        res = run([brew, "list", "--cask", package], check=False)
        return res.returncode == 0

    def install(self, package: str) -> InstallResult:
        brew = _ensure_brew()
        if brew is None:
            return missing_executable_install_result("brew", _BREW_HINT)

        logger.info(f"Installing cask {package} via brew...")
        res = run([brew, "install", "--cask", package], check=False)
        if res.returncode == 0:
            return InstallResult(ok=True, summary=f"Installed cask {package}")
        return InstallResult(
            ok=False, summary=f"Failed to install cask {package}", details=command_details(res)
        )

    def update(self) -> TaskResult:
        # There is no dedicated "cask-only" update; reuse `brew update`.
        return _run_brew_subcommand(["update"], action="brew update (casks)")

    def upgrade(self) -> TaskResult:
        return _run_brew_subcommand(["upgrade", "--cask"], action="brew upgrade --cask")

    def cleanup(self) -> TaskResult:
        # `brew cleanup` also covers casks.
        return _run_brew_subcommand(["cleanup"], action="brew cleanup (casks)")

DarwinBrewManager

Homebrew formula manager for macOS (brew).

Source code in src/personal_os_setup/tasks/managers/darwin_brew.py
class DarwinBrewManager:
    """Homebrew formula manager for macOS (`brew`)."""

    name = "brew"

    def is_installed(self, package: str) -> bool:
        brew = _ensure_brew()
        if brew is None:
            # If brew itself is missing, we cannot reliably report per-package
            # status; treat as not installed.
            return False

        # `brew list --formula <name>` exits 0 if installed, non-zero otherwise.
        res = run([brew, "list", "--formula", package], check=False)
        return res.returncode == 0

    def install(self, package: str) -> InstallResult:
        brew = _ensure_brew()
        if brew is None:
            return missing_executable_install_result("brew", _BREW_HINT)

        logger.info(f"Installing {package} via {self.name}...")
        res = run([brew, "install", package], check=False)
        if res.returncode == 0:
            return InstallResult(ok=True, summary=f"Installed {package}")
        return InstallResult(
            ok=False, summary=f"Failed to install {package}", details=command_details(res)
        )

    def update(self) -> TaskResult:
        return _run_brew_subcommand(["update"], action="brew update")

    def upgrade(self) -> TaskResult:
        return _run_brew_subcommand(["upgrade"], action="brew upgrade")

    def cleanup(self) -> TaskResult:
        return _run_brew_subcommand(["cleanup"], action="brew cleanup")