Skip to main content

build_pacman_install

Function build_pacman_install 

Source
pub fn build_pacman_install<S: AsRef<str>>(
    names: &[S],
    options: &InstallOptions,
) -> Result<CommandSpec>
Expand description

What: Build a pacman install command for official repository packages.

Inputs:

  • names: Package names to install (validated against the safe-name allowlist).
  • options: Flag options (needed, noconfirm; aur_only is ignored).

Output:

  • Ok(CommandSpec) like pacman -S --needed --noconfirm -- <names...>.

Details:

  • Does NOT prefix a privilege tool; use with_privilege for that.
  • Omit --needed (set options.needed = false) for explicit reinstalls, mirroring Pacsea’s reinstall path.
  • A -- operand terminator separates flags from package names so pacman can never reinterpret an operand as an option (defense in depth on top of name validation).

§Errors

Returns ArchToolkitError::InvalidPackageName when a name fails validation, or ArchToolkitError::EmptyInput when names is empty.

§Example

use arch_toolkit::install::build_pacman_install;
use arch_toolkit::types::install::InstallOptions;

let spec = build_pacman_install(&["ripgrep", "fd"], &InstallOptions::default())?;
assert_eq!(spec.to_shell_string(), "pacman -S --needed --noconfirm -- ripgrep fd");