feat: detect and warn if running as root

This commit is contained in:
Andre Toerien
2025-09-26 14:49:12 +02:00
committed by Gideon
parent 7c7e7c3ce4
commit 47b51a8be0
7 changed files with 83 additions and 3 deletions

View File

@@ -295,6 +295,8 @@ pub struct Vim {
#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Misc {
allow_root: Option<bool>,
pre_sudo: Option<bool>,
sudo_command: Option<SudoKind>,
@@ -767,6 +769,10 @@ pub struct CommandLineArgs {
#[arg(long = "show-skipped")]
show_skipped: bool,
/// Suppress warning and confirmation prompt if running as root
#[arg(long = "allow-root")]
allow_root: bool,
/// Tracing filter directives.
///
/// See: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
@@ -1535,6 +1541,16 @@ impl Config {
.unwrap_or(true)
}
pub fn allow_root(&self) -> bool {
self.opt.allow_root
|| self
.config_file
.misc
.as_ref()
.and_then(|misc| misc.allow_root)
.unwrap_or(false)
}
pub fn sudo_command(&self) -> Option<SudoKind> {
self.config_file.misc.as_ref().and_then(|misc| misc.sudo_command)
}