PackageManager

Struct PackageManager 

Source
pub struct PackageManager { /* private fields */ }
Expand description

High-level package manager API

This is the recommended interface for most use cases. It provides a simplified, production-ready API that handles resource management automatically.

§Examples

use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;

    // Single operation
    let result = pm.install("ripgrep").await?;
    println!("Installed {} {}", result.name, result.version);

    // Reuse for multiple operations (benefits from caching + connection reuse)
    let outdated = pm.outdated().await?;
    for pkg in outdated {
        let upgrade = pm.upgrade(&pkg.name).await?;
        println!("Upgraded {} to {}", pkg.name, upgrade.to_version);
    }

    Ok(())
}

Implementations§

Source§

impl PackageManager

Source

pub fn new() -> Result<Self>

Create a new PackageManager with default configuration.

§Errors

Returns an error if the BrewApi client cannot be created.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    Ok(())
}
Source

pub async fn install(&self, name: &str) -> Result<InstallResult>

Install a package from a bottle.

§Arguments
  • name - Formula name (e.g., "ripgrep")
§Returns

Installation result with version, path, and metadata.

§Errors

Returns an error if:

  • Formula not found
  • No bottle available (use upgrade workflow instead)
  • Download or extraction fails
  • Symlink creation fails
§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let result = pm.install("ripgrep").await?;
    println!("Installed {} {}", result.name, result.version);
    println!("  Path: {}", result.path.display());
    println!("  Dependencies: {}", result.dependencies.join(", "));
    Ok(())
}
Source

pub async fn uninstall(&self, name: &str) -> Result<UninstallResult>

Uninstall a package.

§Arguments
  • name - Formula name
§Returns

Uninstall result with metadata.

§Errors

Returns an error if the package is not installed or uninstall fails.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let result = pm.uninstall("ripgrep").await?;
    println!("Uninstalled {} {}", result.name, result.version);
    Ok(())
}
Source

pub async fn upgrade(&self, name: &str) -> Result<UpgradeResult>

Upgrade a package to the latest version.

§Arguments
  • name - Formula name
§Returns

Upgrade result with version information.

§Errors

Returns an error if the package is not installed or upgrade fails.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let result = pm.upgrade("ripgrep").await?;
    println!("Upgraded {} {} → {}", result.name, result.from_version, result.to_version);
    Ok(())
}
Source

pub async fn reinstall(&self, name: &str) -> Result<ReinstallResult>

Reinstall a package (same version, fresh).

§Arguments
  • name - Formula name
§Returns

Reinstall result with metadata.

§Errors

Returns an error if the package is not installed or reinstall fails.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let result = pm.reinstall("ripgrep").await?;
    println!("Reinstalled {} {}", result.name, result.version);
    Ok(())
}
Source

pub async fn search(&self, query: &str) -> Result<SearchResults>

Search for packages matching a query.

§Arguments
  • query - Search query (matches name and description)
§Returns

Search results with formulae and casks.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let results = pm.search("python").await?;
    println!("Found {} formulae", results.formulae.len());
    for f in &results.formulae {
        println!("  {} - {}", f.name, f.desc.as_deref().unwrap_or(""));
    }
    Ok(())
}
Source

pub async fn info(&self, name: &str) -> Result<Formula>

Get information about a package.

§Arguments
  • name - Formula name
§Returns

Complete formula metadata.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let formula = pm.info("ripgrep").await?;
    println!("Name: {}", formula.name);
    println!("Version: {}", formula.versions.stable.unwrap_or_default());
    println!("Description: {}", formula.desc.unwrap_or_default());
    Ok(())
}
Source

pub async fn dependencies(&self, name: &str) -> Result<Dependencies>

Get dependencies of a package.

§Arguments
  • name - Formula name
§Returns

Runtime and build dependencies.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let deps = pm.dependencies("python").await?;
    println!("Runtime dependencies: {}", deps.runtime.len());
    println!("Build dependencies: {}", deps.build.len());
    Ok(())
}
Source

pub async fn uses(&self, name: &str) -> Result<Vec<String>>

Get packages that depend on this package.

§Arguments
  • name - Formula name
§Returns

List of formula names that depend on this one.

Source

pub fn list(&self) -> Result<Vec<InstalledPackage>>

List all installed packages.

§Returns

Vector of installed packages with versions.

§Examples
use kombrucha::PackageManager;

fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let installed = pm.list()?;
    println!("Installed packages: {}", installed.len());
    for pkg in installed {
        println!("  {} {}", pkg.name, pkg.version);
    }
    Ok(())
}
Source

pub async fn outdated(&self) -> Result<Vec<OutdatedPackage>>

Find outdated packages.

§Returns

Vector of outdated packages with upgrade information.

§Examples
use kombrucha::PackageManager;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;
    let outdated = pm.outdated().await?;
    for pkg in outdated {
        if pkg.changeable {
            println!("{} {} → {}", pkg.name, pkg.installed, pkg.latest);
        }
    }
    Ok(())
}
Source

pub fn cleanup(&self, dry_run: bool) -> Result<CleanupResult>

Clean up old package versions.

Removes all but the most recent version of each installed package. This frees up disk space from older versions that are no longer needed.

§Arguments
  • dry_run - If true, only report what would be removed without actually removing
§Returns

Cleanup result with removed packages and space freed.

§Examples
use kombrucha::PackageManager;

fn main() -> anyhow::Result<()> {
    let pm = PackageManager::new()?;

    // Dry run: see what would be removed
    let result = pm.cleanup(true)?;
    println!("Would remove {} versions", result.removed.len());
    println!("Would free {:.1} MB", result.space_freed_mb);

    // Actually clean up
    let result = pm.cleanup(false)?;
    println!("Removed {} versions", result.removed.len());
    println!("Freed {:.1} MB", result.space_freed_mb);

    Ok(())
}
Source

pub fn check(&self) -> Result<HealthCheck>

Check system health.

§Returns

Health check result with issues if any.

Source

pub fn prefix(&self) -> PathBuf

Get the Homebrew prefix path.

Source

pub fn cellar(&self) -> PathBuf

Get the Cellar path.

Source

pub fn api(&self) -> &BrewApi

Get reference to the underlying API client.

For advanced use cases that need direct API access.

Source

pub fn client(&self) -> &Client

Get reference to the underlying HTTP client.

For advanced use cases that need direct HTTP access.

Trait Implementations§

Source§

impl Default for PackageManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,