feat: add pkgr global config
This commit is contained in:
parent
6981fe8f16
commit
401efe3862
3 changed files with 20 additions and 11 deletions
|
@ -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"));
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue