mod cli;
mod config;
mod operations;
use std::io::prelude::*;
use crate::config::{get_config_folder, load_config};
fn main() {
let options = cli::get_cli().get_matches();
let config: config::Config = load_config(get_config_folder().join("config.toml"));
if let Some(options) = options.subcommand_matches("backup") {
let mut has_targets = false;
println!(
r"
/¯¯\ /¯¯\
\_\ \_------_/ /_/
\_ ___ ___ _/
/|____\|_| |_|/____|\
/ \ / \
\ ______\ /______ /
\| =\ /= |/
¯¯
BACKING UP DATA.
PLEASE STAND-BY.
"
);
if let Some(target_str) = options.value_of("TARGET") {
for target in config.targets {
if let Some(tag) = &target.tag {
if tag == target_str {
has_targets = true;
print!("Backing up target: {}... ", tag);
flush();
let res = target.backup();
if let Ok(num) = res {
println!("Done: {} files copied.", num);
} else {
println!(" Error: {}", res.unwrap_err());
}
}
}
}
} else {
for target in config.targets {
if target.optional {
continue;
};
has_targets = true;
print!("Backing up target: ");
if let Some(tag) = &target.tag {
print!("{}... ", tag);
} else {
print!("{}... ", &target.path.display());
}
flush();
let res = target.backup();
if let Ok(num) = res {
println!("Done: {} files copied.", num);
} else {
println!(" Error: {}", res.unwrap_err());
}
}
}
if has_targets {
println!("\nDone.");
} else {
println!("No targets!");
}
} else if let Some(options) = options.subcommand_matches("completion") {
cli::print_completions(options.value_of("SHELL").unwrap().to_owned());
}
}
fn flush() {
std::io::stdout().flush().unwrap();
}