Skip to main content

aur_install_shell_fallback

Function aur_install_shell_fallback 

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

What: Build a shell body that installs AUR packages with runtime helper fallback.

Inputs:

  • names: AUR package names to install (validated).
  • options: Flag options (needed, noconfirm, aur_only).

Output:

  • Ok(String) with a POSIX shell snippet that picks paru, then yay, at execution time, or prints NO_AUR_HELPER_MESSAGE.

Details:

  • Unlike build_aur_install, helper selection happens inside the spawned shell (the terminal’s PATH), not in the calling process — matching Pacsea’s aur_install_body. Prefer this when the command runs in an external terminal whose environment may differ from the caller’s.
  • Names pass the same strict validation as all builders, so interpolating them into the shell string is safe without quoting. A -- operand terminator is emitted before the names for defense in depth.
  • When neither helper exists the body writes NO_AUR_HELPER_MESSAGE to stderr and exits the subshell with status 127, so callers see a failure instead of a successful no-op.

§Errors

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

§Example

use arch_toolkit::install::aur_install_shell_fallback;
use arch_toolkit::types::install::InstallOptions;

let body = aur_install_shell_fallback(&["yay-bin"], &InstallOptions::default())?;
assert!(body.contains("if command -v paru >/dev/null 2>&1; then paru"));
assert!(body.contains("elif command -v yay >/dev/null 2>&1; then yay"));
assert!(body.contains("--noconfirm -- yay-bin"));
assert!(body.contains("exit 127"));