Wojciech Kozlowski
50f4d00e31
Closes #7 Reviewed-on: https://git.wojciechkozlowski.eu/wojtek/musichoard/pulls/15
53 lines
1.1 KiB
Rust
53 lines
1.1 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
use musichoard::{
|
|
database::{
|
|
json::{DatabaseJson, DatabaseJsonFile},
|
|
DatabaseWrite,
|
|
},
|
|
library::{
|
|
beets::{Beets, SystemExecutor},
|
|
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 = Beets::new(Box::new(
|
|
SystemExecutor::default().config(opt.beets_config_file_path.as_deref()),
|
|
));
|
|
|
|
let collection = beets
|
|
.list(&Query::new())
|
|
.expect("failed to query the library");
|
|
|
|
let mut database = DatabaseJson::new(Box::new(DatabaseJsonFile::new(&opt.database_file_path)));
|
|
|
|
database
|
|
.write(&collection)
|
|
.expect("failed to write to the database");
|
|
}
|