61 lines
2.0 KiB
Rust
61 lines
2.0 KiB
Rust
use clap::{crate_authors, crate_description, crate_version, ArgMatches};
|
|
use clap::{App, Arg, SubCommand};
|
|
use client::archive::Archive;
|
|
use dotenv::dotenv;
|
|
use log::{debug, info};
|
|
use std::path::Path;
|
|
fn main() {
|
|
dotenv().ok();
|
|
env_logger::init();
|
|
|
|
let app = App::new("Save Sync")
|
|
.version(crate_version!())
|
|
.author(crate_authors!())
|
|
.about(crate_description!());
|
|
let m = app
|
|
.subcommand(
|
|
SubCommand::with_name("track")
|
|
.arg(
|
|
Arg::with_name("path")
|
|
.value_name("PATH")
|
|
.takes_value(true)
|
|
.required(true)
|
|
.index(1)
|
|
.help("The file / directory which will be tracked"),
|
|
)
|
|
.arg(
|
|
Arg::with_name("friendly")
|
|
.short("f")
|
|
.long("friendly")
|
|
.value_name("NAME")
|
|
.takes_value(true)
|
|
.help("A friendly name for a tracked file / directory"),
|
|
),
|
|
)
|
|
.get_matches();
|
|
|
|
match m.subcommand() {
|
|
("track", Some(sub_m)) => track_path(sub_m),
|
|
_ => eprintln!("No valid subcommand / argument provided"),
|
|
}
|
|
}
|
|
|
|
fn track_path(matches: &ArgMatches) {
|
|
let path = Path::new(matches.value_of("path").unwrap());
|
|
let mut archive = Archive::try_default().expect("Failed to create an Archive struct");
|
|
|
|
if let Some(f_name) = matches.value_of("friendly") {
|
|
info!("Name {} present for {:?}", f_name, path);
|
|
archive
|
|
.track_game_with_friendly(path, f_name)
|
|
.expect("Archive failed to track Game Save Location")
|
|
} else {
|
|
info!("No friendly name present for {:?}", path);
|
|
archive
|
|
.track_game(path)
|
|
.expect("Archive failed to track Game Save Location");
|
|
}
|
|
|
|
info!("Now Tracking: {:?}", path);
|
|
}
|