Expand description
Install module for building package installation, removal, and update commands.
This module builds commands — it never executes them. Every builder
returns a CommandSpec (program + argument vector) that callers can:
- spawn directly via
CommandSpec::to_command(no shell, no quoting bugs), - render for display or terminals via
CommandSpec::to_shell_string, - or simply print (a “dry run” is displaying the command instead of running it).
Functionality:
- Command building — pacman install/remove/update, AUR helper install
- Batch planning — split mixed target lists between pacman and an AUR helper
- Detection — find the preferred AUR helper (
paru→yay) and privilege tool (doas→sudo) onPATH - Shell safety — strict package-name validation and POSIX quoting helpers
§Features
This module requires the install feature flag (which enables deps for
the shared PackageRef/PackageSource types):
[dependencies]
arch-toolkit = { version = "0.3", features = ["install"] }§Examples
§Build and Display an Install Command
use arch_toolkit::install::build_pacman_install;
use arch_toolkit::types::install::InstallOptions;
let spec = build_pacman_install(&["ripgrep", "fd"], &InstallOptions::default())?;
// Dry run: display instead of executing
println!("Would run: {}", spec.to_shell_string());§Detect Tools and Plan a Mixed Batch
use arch_toolkit::install::{build_batch_install, detect_aur_helper, detect_privilege_tool};
use arch_toolkit::types::install::InstallOptions;
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,
detect_aur_helper(),
detect_privilege_tool(),
&InstallOptions::default(),
None::<&std::collections::HashSet<String>>,
)?;
for command in &plan.commands {
println!("{command}");
}§Remove Packages with Cascade Control
use arch_toolkit::install::{build_remove_command, with_privilege};
use arch_toolkit::types::install::{CascadeMode, PrivilegeTool};
let spec = with_privilege(
PrivilegeTool::Sudo,
build_remove_command(&["old-package"], CascadeMode::CascadeWithConfigs, true)?,
);
assert_eq!(spec.to_shell_string(), "sudo pacman -Rns --noconfirm -- old-package");§Execute a Built Command (caller’s decision)
use arch_toolkit::install::build_update_command;
let spec = build_update_command(None, true);
let status = spec.to_command().status()?;
println!("Update exited with: {status}");Re-exports§
pub use crate::types::install::AurHelper;pub use crate::types::install::CascadeMode;pub use crate::types::install::CommandSpec;pub use crate::types::install::InstallOptions;pub use crate::types::install::PrivilegeTool;
Structs§
- Install
Plan - What: The result of planning a batch installation.
Constants§
- NO_
AUR_ HELPER_ MESSAGE - Message printed by shell-fallback bodies when no AUR helper is installed.
Functions§
- aur_
install_ shell_ fallback - What: Build a shell body that installs AUR packages with runtime helper fallback.
- aur_
update_ shell_ fallback - What: Build a shell body that updates AUR packages with runtime helper fallback.
- build_
aur_ install - What: Build an AUR helper install command for AUR packages.
- build_
aur_ update_ command - What: Build an AUR-only update command (
-Sua). - build_
batch_ install - What: Plan a batch installation by splitting targets between pacman and an AUR helper.
- build_
force_ sync_ update_ command - What: Build a full-system update command that force-refreshes sync databases.
- build_
pacman_ install - What: Build a pacman install command for official repository packages.
- build_
remove_ command - What: Build a pacman remove command with the requested cascade level.
- build_
update_ command - What: Build a full-system update command.
- command_
on_ path - What: Determine whether a command is available on the Unix
PATH. - detect_
aur_ helper - What: Detect the preferred AUR helper available on
PATH. - detect_
privilege_ tool - What: Detect the preferred privilege escalation tool available on
PATH. - is_
aur_ helper_ available - What: Check whether a specific AUR helper is available on
PATH. - is_
privilege_ tool_ available - What: Check whether a specific privilege tool is available on
PATH. - is_
safe_ package_ name - What: Check whether a package name matches the strict allowlist used for install commands.
- resolve_
command_ on_ path - What: Resolve an executable on
PATHor by explicit path. - shell_
single_ quote - What: Safely single-quote an arbitrary string for POSIX shells.
- validate_
package_ names - What: Validate a list of package names against the strict install-command allowlist.
- with_
privilege - What: Wrap a command with a privilege escalation tool prefix.