parent
fcbde5aecb
commit
c869489919
@ -37,7 +37,6 @@ jobs:
|
||||
--ignore "examples/*"
|
||||
--ignore "tests/*"
|
||||
--ignore "src/main.rs"
|
||||
--ignore "src/bin/musichoard-edit.rs"
|
||||
--excl-line "^#\[derive|unimplemented\!\(|unreachable\!\("
|
||||
--excl-start "GRCOV_EXCL_START|mod tests \{"
|
||||
--excl-stop "GRCOV_EXCL_STOP"
|
||||
|
@ -45,10 +45,6 @@ tui = ["crossterm", "ratatui", "tui-input"]
|
||||
name = "musichoard"
|
||||
required-features = ["bin", "database-json", "library-beets", "library-beets-ssh", "musicbrainz", "tui"]
|
||||
|
||||
[[bin]]
|
||||
name = "musichoard-edit"
|
||||
required-features = ["bin", "database-json"]
|
||||
|
||||
[[example]]
|
||||
name = "musicbrainz-api---browse"
|
||||
path = "examples/musicbrainz_api/browse.rs"
|
||||
|
@ -62,7 +62,6 @@ grcov codecov/debug/profraw \
|
||||
--ignore "examples/*" \
|
||||
--ignore "tests/*" \
|
||||
--ignore "src/main.rs" \
|
||||
--ignore "src/bin/musichoard-edit.rs" \
|
||||
--excl-line "^#\[derive|unimplemented\!\(|unreachable\!\(" \
|
||||
--excl-start "GRCOV_EXCL_START|mod tests \{" \
|
||||
--excl-stop "GRCOV_EXCL_STOP" \
|
||||
|
@ -1,257 +0,0 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use structopt::{clap::AppSettings, StructOpt};
|
||||
|
||||
use musichoard::{
|
||||
collection::{album::AlbumId, artist::ArtistId},
|
||||
external::database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
IMusicHoardDatabase, MusicHoard, MusicHoardBuilder, NoLibrary,
|
||||
};
|
||||
|
||||
type MH = MusicHoard<JsonDatabase<JsonDatabaseFileBackend>, NoLibrary>;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(about = "musichoard-edit: edit the MusicHoard database",
|
||||
global_settings=&[AppSettings::DeriveDisplayOrder])]
|
||||
struct Opt {
|
||||
#[structopt(
|
||||
long = "database",
|
||||
help = "Database file path",
|
||||
default_value = "database.json"
|
||||
)]
|
||||
database_file_path: PathBuf,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
enum Command {
|
||||
#[structopt(about = "Modify artist information")]
|
||||
Artist(ArtistOpt),
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct ArtistOpt {
|
||||
// For some reason, not specyfing the artist name with the `long` name makes StructOpt failed
|
||||
// for inexplicable reason. For example, it won't recognise `Abadde` or `Abadden` as a name and
|
||||
// will insteady try to process it as a command.
|
||||
#[structopt(long, help = "The name of the artist")]
|
||||
name: String,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
command: ArtistCommand,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
enum ArtistCommand {
|
||||
#[structopt(about = "Add a new artist to the collection")]
|
||||
Add,
|
||||
#[structopt(about = "Remove an artist from the collection")]
|
||||
Remove,
|
||||
#[structopt(about = "Edit the artist's sort name")]
|
||||
Sort(SortCommand),
|
||||
#[structopt(about = "Edit a property of an artist")]
|
||||
Property(PropertyCommand),
|
||||
#[structopt(about = "Modify the artist's album information")]
|
||||
Album(AlbumOpt),
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
enum SortCommand {
|
||||
#[structopt(about = "Set the provided name as the artist's sort name")]
|
||||
Set(SortValue),
|
||||
#[structopt(about = "Clear the artist's sort name")]
|
||||
Clear,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct SortValue {
|
||||
#[structopt(help = "The sort name")]
|
||||
sort: String,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
enum PropertyCommand {
|
||||
#[structopt(about = "Add values to the property without overwriting existing values")]
|
||||
Add(PropertyValue),
|
||||
#[structopt(about = "Remove values from the property")]
|
||||
Remove(PropertyValue),
|
||||
#[structopt(about = "Set the property's values overwriting any existing values")]
|
||||
Set(PropertyValue),
|
||||
#[structopt(about = "Clear all values of a property")]
|
||||
Clear(PropertyName),
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct PropertyValue {
|
||||
#[structopt(help = "The name of the property")]
|
||||
property: String,
|
||||
#[structopt(help = "The list of values")]
|
||||
values: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct PropertyName {
|
||||
#[structopt(help = "The name of the property")]
|
||||
property: String,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct AlbumOpt {
|
||||
// Using `long` for consistency with `ArtistOpt`.
|
||||
#[structopt(long, help = "The title of the album")]
|
||||
title: String,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
command: AlbumCommand,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
enum AlbumCommand {
|
||||
#[structopt(about = "Edit the album's sequence value")]
|
||||
Seq(AlbumSeqCommand),
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
enum AlbumSeqCommand {
|
||||
#[structopt(about = "Set the sequence value overwriting any existing value")]
|
||||
Set(AlbumSeqValue),
|
||||
#[structopt(about = "Clear the sequence value")]
|
||||
Clear,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct AlbumSeqValue {
|
||||
#[structopt(help = "The new sequence value")]
|
||||
value: u8,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
fn handle(self, music_hoard: &mut MH) {
|
||||
match self {
|
||||
Command::Artist(artist_opt) => artist_opt.handle(music_hoard),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ArtistOpt {
|
||||
fn handle(self, music_hoard: &mut MH) {
|
||||
self.command.handle(music_hoard, &self.name)
|
||||
}
|
||||
}
|
||||
|
||||
impl ArtistCommand {
|
||||
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
||||
match self {
|
||||
ArtistCommand::Add => {
|
||||
music_hoard
|
||||
.add_artist(ArtistId::new(artist_name))
|
||||
.expect("failed to add artist");
|
||||
}
|
||||
ArtistCommand::Remove => {
|
||||
music_hoard
|
||||
.remove_artist(ArtistId::new(artist_name))
|
||||
.expect("failed to remove artist");
|
||||
}
|
||||
ArtistCommand::Sort(sort_command) => {
|
||||
sort_command.handle(music_hoard, artist_name);
|
||||
}
|
||||
ArtistCommand::Property(property_command) => {
|
||||
property_command.handle(music_hoard, artist_name);
|
||||
}
|
||||
ArtistCommand::Album(album_opt) => {
|
||||
album_opt.handle(music_hoard, artist_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SortCommand {
|
||||
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
||||
match self {
|
||||
SortCommand::Set(artist_sort_value) => music_hoard
|
||||
.set_artist_sort(ArtistId::new(artist_name), artist_sort_value.sort)
|
||||
.expect("faild to set artist sort name"),
|
||||
SortCommand::Clear => music_hoard
|
||||
.clear_artist_sort(ArtistId::new(artist_name))
|
||||
.expect("failed to clear artist sort name"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyCommand {
|
||||
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
||||
match self {
|
||||
PropertyCommand::Add(property_value) => music_hoard
|
||||
.add_to_artist_property(
|
||||
ArtistId::new(artist_name),
|
||||
property_value.property,
|
||||
property_value.values,
|
||||
)
|
||||
.expect("failed to add values to property"),
|
||||
PropertyCommand::Remove(property_value) => music_hoard
|
||||
.remove_from_artist_property(
|
||||
ArtistId::new(artist_name),
|
||||
property_value.property,
|
||||
property_value.values,
|
||||
)
|
||||
.expect("failed to remove values from property"),
|
||||
PropertyCommand::Set(property_value) => music_hoard
|
||||
.set_artist_property(
|
||||
ArtistId::new(artist_name),
|
||||
property_value.property,
|
||||
property_value.values,
|
||||
)
|
||||
.expect("failed to set property"),
|
||||
PropertyCommand::Clear(property_name) => music_hoard
|
||||
.clear_artist_property(ArtistId::new(artist_name), property_name.property)
|
||||
.expect("failed to clear property"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AlbumOpt {
|
||||
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
||||
self.command.handle(music_hoard, artist_name, &self.title)
|
||||
}
|
||||
}
|
||||
|
||||
impl AlbumCommand {
|
||||
fn handle(self, music_hoard: &mut MH, artist_name: &str, album_name: &str) {
|
||||
match self {
|
||||
AlbumCommand::Seq(seq_command) => {
|
||||
seq_command.handle(music_hoard, artist_name, album_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AlbumSeqCommand {
|
||||
fn handle(self, music_hoard: &mut MH, artist_name: &str, album_name: &str) {
|
||||
match self {
|
||||
AlbumSeqCommand::Set(seq_value) => music_hoard
|
||||
.set_album_seq(
|
||||
ArtistId::new(artist_name),
|
||||
AlbumId::new(album_name),
|
||||
seq_value.value,
|
||||
)
|
||||
.expect("failed to set sequence value"),
|
||||
AlbumSeqCommand::Clear => music_hoard
|
||||
.clear_album_seq(ArtistId::new(artist_name), AlbumId::new(album_name))
|
||||
.expect("failed to clear sequence value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
let db = JsonDatabase::new(JsonDatabaseFileBackend::new(&opt.database_file_path));
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default().set_database(db).build();
|
||||
music_hoard
|
||||
.reload_database()
|
||||
.expect("failed to load MusicHoard database");
|
||||
opt.command.handle(&mut music_hoard);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user