Skip to main content

pacsea/util/
pacman.rs

1//! Pacman command execution utilities.
2//!
3//! This module provides functions for executing pacman commands and handling
4//! common error cases.
5
6use crate::util::command::run_capture;
7
8/// Result type alias for pacman command operations.
9type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
10
11/// What: Execute `pacman` with the provided arguments and capture stdout.
12///
13/// Inputs:
14/// - `args`: Slice of CLI arguments passed directly to the pacman binary.
15///
16/// Output:
17/// - Returns the command's stdout as a UTF-8 string or propagates execution/parsing errors.
18///
19/// # Errors
20/// - Returns `Err` when `pacman` command execution fails (I/O error or pacman not found)
21/// - Returns `Err` when `pacman` exits with non-zero status
22/// - Returns `Err` when stdout cannot be decoded as UTF-8
23///
24/// Details:
25/// - Thin wrapper over [`crate::util::command::run_capture`], which handles the
26///   spawn/exit tracing; failures are boxed into the local `Result` alias.
27/// - Used internally by index and logic helpers to keep command invocation boilerplate centralized.
28pub fn run_pacman(args: &[&str]) -> Result<String> {
29    Ok(run_capture("pacman", args)?)
30}