refactor: route sudo usage through Sudo::execute*

This commit is contained in:
Andre Toerien
2025-06-25 15:59:02 +02:00
committed by Gideon
parent 012a6bbde3
commit a95dd1e037
16 changed files with 303 additions and 321 deletions

View File

@@ -1,4 +1,5 @@
use std::ffi::OsStr;
use std::path::Path;
use std::path::PathBuf;
use color_eyre::eyre::Context;
@@ -69,6 +70,15 @@ impl Sudo {
which(kind.as_ref()).map(|path| Self { path, kind })
}
/// Gets the path to the `sudo` binary. Do not use this to execute `sudo` directly - either use
/// [`Sudo::elevate`], or if you need to specify arguments to `sudo`, use [`Sudo::elevate_opts`].
/// This way, sudo options can be specified generically and the actual arguments customized
/// depending on the sudo kind.
#[allow(unused)]
pub fn path(&self) -> &Path {
self.path.as_ref()
}
/// Elevate permissions with `sudo`.
///
/// This helps prevent blocking `sudo` prompts from stopping the run in the middle of a
@@ -278,9 +288,3 @@ pub enum SudoKind {
Run0,
Please,
}
impl AsRef<OsStr> for Sudo {
fn as_ref(&self) -> &OsStr {
self.path.as_ref()
}
}