musichoard/src/main.rs

55 lines
1.2 KiB
Rust

use std::path::PathBuf;
use structopt::StructOpt;
use musichoard::{
database::{
json::{JsonDatabase, JsonDatabaseFileBackend},
DatabaseWrite,
},
library::{
beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
Library, Query,
},
};
#[derive(StructOpt)]
struct Opt {
#[structopt(
short = "b",
long = "beets-config",
name = "beets config file path",
parse(from_os_str)
)]
beets_config_file_path: Option<PathBuf>,
#[structopt(
short = "d",
long = "database",
name = "database file path",
default_value = "database.json",
parse(from_os_str)
)]
database_file_path: PathBuf,
}
fn main() {
let opt = Opt::from_args();
let mut beets = BeetsLibrary::new(Box::new(unsafe {
BeetsLibraryCommandExecutor::default().config(opt.beets_config_file_path.as_deref())
}));
let collection = beets
.list(&Query::new())
.expect("failed to query the library");
let mut database = JsonDatabase::new(Box::new(JsonDatabaseFileBackend::new(
&opt.database_file_path,
)));
database
.write(&collection)
.expect("failed to write to the database");
}