init
This commit is contained in:
commit
b416507e4a
8 changed files with 326 additions and 0 deletions
40
src/main.rs
Normal file
40
src/main.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use backup::run_backup;
|
||||
|
||||
mod backup;
|
||||
mod config;
|
||||
|
||||
fn main() {
|
||||
let args = std::env::args().collect::<Vec<_>>();
|
||||
|
||||
if let Some(conf) = args.get(1) {
|
||||
let conf = toml::from_str(&std::fs::read_to_string(conf).unwrap()).unwrap();
|
||||
run_backup(conf);
|
||||
} else {
|
||||
println!("Usage: bk <config>");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_command(cmd: &[&str]) -> (String, String) {
|
||||
println!("--> {} ", cmd.join(" "));
|
||||
|
||||
let mut cmd_setup = std::process::Command::new(cmd[0]);
|
||||
let mut cmd_setup = cmd_setup.args(cmd.iter().skip(1).collect::<Vec<_>>());
|
||||
|
||||
cmd_setup = cmd_setup
|
||||
.stdout(std::process::Stdio::inherit())
|
||||
.stdin(std::process::Stdio::inherit());
|
||||
|
||||
let child = cmd_setup.spawn().unwrap();
|
||||
|
||||
let status = child.wait_with_output().unwrap();
|
||||
assert!(status.status.success());
|
||||
|
||||
let output = String::from_utf8(status.stdout).unwrap();
|
||||
let stderr = String::from_utf8(status.stderr).unwrap();
|
||||
|
||||
if !stderr.trim().is_empty() {
|
||||
eprintln!("{stderr}");
|
||||
}
|
||||
|
||||
(output, stderr)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue