feat: add pkgr global config
All checks were successful
/ check (push) Successful in 40s

This commit is contained in:
Didier Slof 2023-07-19 15:35:51 +02:00
parent c12b78b3c1
commit b115b91ecb
Signed by: didier
GPG key ID: 01E71F18AA4398E5
3 changed files with 20 additions and 11 deletions

View file

@ -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"));

View file

@ -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<Config, String> {
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::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<std::process::Child> {
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)
}
}