You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
postsack/src/bin/cli.rs

61 lines
1.4 KiB
Rust

3 years ago
use eyre::Result;
use std::{
io::{stdout, Write},
thread::sleep,
time::Duration,
};
use gmaildb::{
self,
importer::{Progress, State},
};
fn main() -> Result<()> {
gmaildb::setup_tracing();
3 years ago
let config = gmaildb::make_config();
let importer = gmaildb::importer::gmail_importer(&config);
3 years ago
let adapter = gmaildb::importer::Adapter::new();
let handle = adapter.process(importer)?;
3 years ago
let mut stdout = stdout();
loop {
match adapter.finished() {
Ok(State {
finishing: true, ..
}) => {
println!("Finishing import...");
}
Ok(State { done: true, .. }) => {
break;
}
_ => (),
};
match adapter.read_count() {
Ok(Progress { count, total }) => {
print!("\rReading {}/{}...", count, total);
}
_ => (),
};
match adapter.write_count() {
Ok(Progress { count, total }) => {
print!("\rWriting to DB {}/{}...", count, total);
}
_ => (),
};
stdout.flush().unwrap();
sleep(Duration::from_millis(50));
}
match handle.join() {
Err(e) => println!("Error: {:?}", e),
Ok(Err(e)) => println!("Error: {:?}", e),
_ => (),
}
Ok(())
}