refactor: move readwise files to it's own binary
This commit is contained in:
parent
b31502fb37
commit
2827193fd6
6 changed files with 105 additions and 73 deletions
|
|
@ -1,15 +1,10 @@
|
|||
use clap::{CommandFactory, Parser};
|
||||
use clap::Parser;
|
||||
use figment::{
|
||||
providers::{Env, Serialized},
|
||||
Figment,
|
||||
};
|
||||
use readwise_bulk_upload::config::{Command, Config};
|
||||
use readwise_bulk_upload::readwise::DocumentPayload;
|
||||
use lib_sync_core::task_manager::{TaskManager, TaskStatus};
|
||||
use readwise_bulk_upload::{Error, Result};
|
||||
use std::fs::File;
|
||||
use directories::ProjectDirs;
|
||||
use tabled::Table;
|
||||
use cli::config::Config;
|
||||
use cli::Result;
|
||||
use tracing_subscriber;
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -24,47 +19,5 @@ async fn main() -> Result<()> {
|
|||
.with_max_level(args.log_level())
|
||||
.init();
|
||||
|
||||
run(&cli.command).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn run(command: &Command) -> Result<()> {
|
||||
let project_dir = ProjectDirs::from("", "", env!("CARGO_PKG_NAME"))
|
||||
.ok_or(lib_sync_core::error::Error::Unhandled("Could not get standard directories"))?;
|
||||
|
||||
let task_manager = TaskManager::new(project_dir.data_dir()).await?;
|
||||
|
||||
match command {
|
||||
Command::LoadTasks { path } => {
|
||||
let file = File::open(path).map_err(|_| {
|
||||
Error::Runtime(format!(
|
||||
r#"The file "{}" could not be open"#,
|
||||
path.display()
|
||||
))
|
||||
})?;
|
||||
|
||||
let documents: Vec<DocumentPayload> = serde_json::from_reader(file)?;
|
||||
|
||||
|
||||
task_manager.load_tasks(documents).await?;
|
||||
}
|
||||
Command::Query => {
|
||||
let tasks = task_manager.get_tasks::<DocumentPayload>(None, Some(25)).await?;
|
||||
|
||||
println!("{}", Table::new(tasks));
|
||||
}
|
||||
Command::Run => {
|
||||
task_manager.run_tasks::<DocumentPayload>(|task| {
|
||||
println!("{}", task.get_key());
|
||||
|
||||
TaskStatus::Completed
|
||||
}).await?;
|
||||
}
|
||||
Command::None => {
|
||||
Config::command().print_help()?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue