feat: add pkgr global config

This commit is contained in:
Strix 2023-10-14 22:39:44 +02:00
parent 6981fe8f16
commit 401efe3862
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
3 changed files with 20 additions and 11 deletions

View file

@ -114,9 +114,14 @@ impl Command {
error!("Error message."); error!("Error message.");
info!(""); 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() .spawn()
.unwrap(); .unwrap();
if let Ok(user) = std::env::var("SUDO_USER") {
Process::command(vec!["sh", "-c", "echo sudo_user: $SUDO_USER"])
.spawn()
.unwrap();
}
info!(""); info!("");
info!("PKGR VERSION: {}", env!("CARGO_PKG_VERSION")); info!("PKGR VERSION: {}", env!("CARGO_PKG_VERSION"));

View file

@ -6,6 +6,14 @@ pub struct Config {
pub build_by_default: bool, pub build_by_default: bool,
} }
impl Default for Config {
fn default() -> Config {
Config {
build_by_default: false,
}
}
}
impl Config { impl Config {
pub fn from_path(path: &str) -> Result<Config, String> { pub fn from_path(path: &str) -> Result<Config, String> {
match std::fs::read_to_string(path) { 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,
}
}
}

View file

@ -1,6 +1,6 @@
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::process::Command; use std::process::Command;
use log::info; use log::{info, trace};
pub struct Process { pub struct Process {
@ -19,6 +19,7 @@ impl Process {
} }
pub fn spawn(&self) -> std::io::Result<std::process::Child> { pub fn spawn(&self) -> std::io::Result<std::process::Child> {
trace!("Spawning process: {:?}", self.command);
let mut child = Command::new(&self.command[0]) let mut child = Command::new(&self.command[0])
.args(&self.command[1..]) .args(&self.command[1..])
.current_dir(self.cwd.clone().unwrap_or(".".to_string())) .current_dir(self.cwd.clone().unwrap_or(".".to_string()))
@ -32,10 +33,10 @@ impl Process {
.stdout(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())
.spawn()?; .spawn()?;
let stdout = child.stdout.take().unwrap(); let stdout = child.stdout.take().unwrap();
let stderr = child.stderr.take().unwrap(); let stderr = child.stderr.take().unwrap();
trace!("Processing lines from stdout and stderr");
for line in BufReader::new(stdout).lines() { for line in BufReader::new(stdout).lines() {
info!(target: "command:stdout", "{}", line.unwrap()); info!(target: "command:stdout", "{}", line.unwrap());
} }
@ -44,6 +45,9 @@ impl Process {
info!(target: "command:stderr", "{}", line.unwrap()); info!(target: "command:stderr", "{}", line.unwrap());
} }
trace!("End of process");
trace!("Returning child");
Ok(child) Ok(child)
} }
} }