Skip to main content

detect_privilege_tool

Function detect_privilege_tool 

Source
pub fn detect_privilege_tool() -> Option<PrivilegeTool>
Expand description

What: Detect the preferred privilege escalation tool available on PATH.

Inputs: None.

Output:

  • Some(PrivilegeTool::Doas) when doas is available.
  • Some(PrivilegeTool::Sudo) when only sudo is available.
  • None when neither tool is installed.

Details:

  • Preference order (doas first, sudo fallback) matches Pacsea’s Auto privilege mode: sudo is present on most systems by default, so an installed doas signals a deliberate user choice.
  • Callers with an explicit user configuration should honor it via is_privilege_tool_available instead of calling this.
  • Password handling is intentionally out of scope for arch-toolkit.

§Example

use arch_toolkit::install::detect_privilege_tool;

match detect_privilege_tool() {
    Some(tool) => println!("Privilege tool: {tool}"),
    None => eprintln!("No privilege tool (sudo/doas) found."),
}