This repository was archived by the owner on Jul 27, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
64 lines (50 loc) · 1.51 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// #![feature(conservative_impl_trait)]
extern crate chrono;
#[macro_use]
extern crate clap;
extern crate env_logger;
#[macro_use]
extern crate error_chain;
extern crate glob;
extern crate futures;
extern crate ignore;
#[macro_use]
extern crate log;
extern crate notify;
extern crate rand;
extern crate rusqlite;
use std::path::PathBuf;
mod errors;
use errors::*;
mod squirrel;
mod path_filter;
quick_main!(run);
fn run() -> Result<()> {
let matches = clap_app!(code_squirrel =>
(version: crate_version!())
(author: crate_authors!("\n"))
(about: crate_description!())
(@subcommand daemon =>
(about: "run the daemon to monitor a directory")
)
(@subcommand show =>
(about: "show revisions to files matching GLOB")
(@arg GLOB: +required "The glob to match against")
)
).get_matches();
env_logger::init()?;
let watched_dir = PathBuf::from(".").canonicalize().expect(
"Unable to determine the path to the current directory",
);
let stash_path = watched_dir.join(".backup");
if let Some(_) = matches.subcommand_matches("daemon") {
return squirrel::run_squirrel(&watched_dir, &stash_path);
}
if let Some(matches) = matches.subcommand_matches("show") {
let glob = matches.value_of("GLOB").unwrap();
let glob = glob::Pattern::new(&glob)?;
return squirrel::list_snapshots(&stash_path, glob);
}
println!("{}", matches.usage());
Err(ErrorKind::NoCommand.into())
}