Skip to main content

with_privilege

Function with_privilege 

Source
pub fn with_privilege(tool: PrivilegeTool, spec: CommandSpec) -> CommandSpec
Expand description

What: Wrap a command with a privilege escalation tool prefix.

Inputs:

  • tool: The privilege tool (sudo or doas).
  • spec: The command to wrap.

Output:

  • New CommandSpec like sudo pacman -S ....

Details:

  • Pure transformation: the original program becomes the first argument.
  • Do NOT wrap AUR helper commands; helpers escalate internally.
  • Password handling (stdin piping, askpass) is intentionally out of scope.

ยงExample

use arch_toolkit::install::{build_update_command, with_privilege};
use arch_toolkit::types::install::PrivilegeTool;

let spec = with_privilege(PrivilegeTool::Sudo, build_update_command(None, true));
assert_eq!(spec.to_shell_string(), "sudo pacman -Syu --noconfirm");