Add sudo_command option (#379)

This allows the user to specify the preferred sudo command to be used
instead of the command chosen by Sudo::detect
This commit is contained in:
Thomas de Queiroz Barros
2023-03-13 19:23:37 +00:00
committed by GitHub
parent 462016e51e
commit a3628d0d49
4 changed files with 21 additions and 3 deletions

View File

@@ -4,6 +4,8 @@ use std::path::PathBuf;
use color_eyre::eyre::Context;
use color_eyre::eyre::Result;
use serde::Deserialize;
use strum::AsRefStr;
use crate::command::CommandExt;
use crate::execution_context::ExecutionContext;
@@ -31,6 +33,11 @@ impl Sudo {
.map(|(path, kind)| Self { path, kind })
}
/// Create Sudo from SudoKind, if found in the system
pub fn new(kind: SudoKind) -> Option<Self> {
which(kind.as_ref()).map(|path| Self { path, kind })
}
/// Elevate permissions with `sudo`.
///
/// This helps prevent blocking `sudo` prompts from stopping the run in the middle of a
@@ -100,8 +107,10 @@ impl Sudo {
}
}
#[derive(Clone, Copy, Debug)]
enum SudoKind {
#[derive(Clone, Copy, Debug, Deserialize, AsRefStr)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum SudoKind {
Doas,
Please,
Sudo,