From 401efe38623d6477c8ab574daafcec447aefd60b Mon Sep 17 00:00:00 2001 From: Raine Date: Sat, 14 Oct 2023 22:39:44 +0200 Subject: [PATCH] feat: add pkgr global config --- pkgr/src/commands.rs | 7 ++++++- pkgr/src/config/mod.rs | 16 ++++++++-------- pkgr/src/process.rs | 8 ++++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkgr/src/commands.rs b/pkgr/src/commands.rs index 6d8e139..d63e2e3 100644 --- a/pkgr/src/commands.rs +++ b/pkgr/src/commands.rs @@ -114,9 +114,14 @@ impl Command { error!("Error message."); info!(""); - Process::command(vec!["sh", "-c", "echo whoami: $(whoami)"].iter_mut().map(|s| s.to_string()).collect()) + Process::command(vec!["sh", "-c", "echo whoami: $(whoami)"]) .spawn() .unwrap(); + if let Ok(user) = std::env::var("SUDO_USER") { + Process::command(vec!["sh", "-c", "echo sudo_user: $SUDO_USER"]) + .spawn() + .unwrap(); + } info!(""); info!("PKGR VERSION: {}", env!("CARGO_PKG_VERSION")); diff --git a/pkgr/src/config/mod.rs b/pkgr/src/config/mod.rs index 29f4936..4bb3397 100644 --- a/pkgr/src/config/mod.rs +++ b/pkgr/src/config/mod.rs @@ -6,6 +6,14 @@ pub struct Config { pub build_by_default: bool, } +impl Default for Config { + fn default() -> Config { + Config { + build_by_default: false, + } + } +} + impl Config { pub fn from_path(path: &str) -> Result { match std::fs::read_to_string(path) { @@ -17,11 +25,3 @@ impl Config { } } } - -impl Default for Config { - fn default() -> Config { - Config { - build_by_default: false, - } - } -} \ No newline at end of file diff --git a/pkgr/src/process.rs b/pkgr/src/process.rs index 727529f..f6f4e21 100644 --- a/pkgr/src/process.rs +++ b/pkgr/src/process.rs @@ -1,6 +1,6 @@ use std::io::{BufRead, BufReader}; use std::process::Command; -use log::info; +use log::{info, trace}; pub struct Process { @@ -19,6 +19,7 @@ impl Process { } pub fn spawn(&self) -> std::io::Result { + trace!("Spawning process: {:?}", self.command); let mut child = Command::new(&self.command[0]) .args(&self.command[1..]) .current_dir(self.cwd.clone().unwrap_or(".".to_string())) @@ -32,10 +33,10 @@ impl Process { .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) .spawn()?; - let stdout = child.stdout.take().unwrap(); let stderr = child.stderr.take().unwrap(); + trace!("Processing lines from stdout and stderr"); for line in BufReader::new(stdout).lines() { info!(target: "command:stdout", "{}", line.unwrap()); } @@ -44,6 +45,9 @@ impl Process { info!(target: "command:stderr", "{}", line.unwrap()); } + trace!("End of process"); + + trace!("Returning child"); Ok(child) } }