pub fn build_batch_install<S: BuildHasher>(
targets: &[PackageRef],
helper: Option<AurHelper>,
privilege: Option<PrivilegeTool>,
options: &InstallOptions,
installed: Option<&HashSet<String, S>>,
) -> Result<InstallPlan>Expand description
What: Plan a batch installation by splitting targets between pacman and an AUR helper.
Inputs:
targets: Packages to install; thesourcefield routes each to pacman or the helper.helper: AUR helper to use for AUR targets. Required when any target is from the AUR.privilege: WhenSome, the pacman command is wrapped (e.g.,sudo pacman ...). AUR helper commands are never wrapped (helpers escalate internally).options: Flag options;options.neededis refined per group wheninstalledis given.installed: Optional set of installed package names. When any name in a group is already installed,--neededis dropped for that group so reinstalls proceed — mirroring Pacsea’s batch reinstall detection. PassNoneto useoptions.neededas-is.
Output:
Ok(InstallPlan)with grouped commands and routed names.
Details:
- Official packages are grouped into a single
pacmaninvocation, AUR packages into a single helper invocation (from Pacsea’sbuild_batch_install_command). - Both grouped commands inherit strict name validation and the
--operand terminator from the underlying direct builders. - Empty
targetsproduces an empty plan (no error), so callers can pass through selection results unchecked. - arch-toolkit never executes the plan; run the commands with
spec.to_command()or display them withspec.to_shell_string()(dry run).
§Errors
ArchToolkitError::InvalidInputwhen AUR targets are present buthelperisNone.ArchToolkitError::InvalidPackageNamewhen a target name fails validation.
§Example
use arch_toolkit::install::build_batch_install;
use arch_toolkit::types::install::{AurHelper, InstallOptions, PrivilegeTool};
use arch_toolkit::{PackageRef, PackageSource};
let targets = vec![
PackageRef::official("ripgrep", "14.0.0", "extra", "x86_64"),
PackageRef::aur("yay-bin", "12.0.0"),
];
let plan = build_batch_install(
&targets,
Some(AurHelper::Paru),
Some(PrivilegeTool::Sudo),
&InstallOptions::default(),
None::<&std::collections::HashSet<String>>,
)?;
assert_eq!(plan.commands.len(), 2);
assert_eq!(
plan.commands[0].to_shell_string(),
"sudo pacman -S --needed --noconfirm -- ripgrep"
);
assert_eq!(
plan.commands[1].to_shell_string(),
"paru -S --aur --needed --noconfirm -- yay-bin"
);