refactor: route sudo usage through Sudo::execute*
This commit is contained in:
16
src/sudo.rs
16
src/sudo.rs
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user