use std::{env, process::exit};
use anyhow::{Result, bail};
use nix::unistd::Uid;
use tokio::process::Command;
pub async fn run_with_root() -> Result<()> {
if !Uid::effective().is_root() {
let args: Vec<String> = env::args().collect();
let status = Command::new("sudo").args(&args).status().await?;
exit(status.code().unwrap_or(1));
}
Ok(())
}
pub fn run_with_noroot() -> Result<()> {
if Uid::effective().is_root() {
bail!("Do not use sudo on this command!");
}
Ok(())
}