Remove some unneeded functionality
This commit is contained in:
parent
c6424ec036
commit
735cd00ab7
@ -51,8 +51,6 @@ enum ArtistCommand {
|
|||||||
Remove,
|
Remove,
|
||||||
#[structopt(about = "Edit the artist's sort name")]
|
#[structopt(about = "Edit the artist's sort name")]
|
||||||
Sort(SortCommand),
|
Sort(SortCommand),
|
||||||
#[structopt(name = "musicbrainz", about = "Edit the MusicBrainz URL of an artist")]
|
|
||||||
MusicBrainz(MusicBrainzCommand),
|
|
||||||
#[structopt(about = "Edit a property of an artist")]
|
#[structopt(about = "Edit a property of an artist")]
|
||||||
Property(PropertyCommand),
|
Property(PropertyCommand),
|
||||||
#[structopt(about = "Modify the artist's album information")]
|
#[structopt(about = "Modify the artist's album information")]
|
||||||
@ -73,20 +71,6 @@ struct SortValue {
|
|||||||
sort: String,
|
sort: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
|
||||||
enum MusicBrainzCommand {
|
|
||||||
#[structopt(about = "Set the MusicBrainz URL overwriting any existing value")]
|
|
||||||
Set(MusicBrainzValue),
|
|
||||||
#[structopt(about = "Clear the MusicBrainz URL)")]
|
|
||||||
Clear,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
|
||||||
struct MusicBrainzValue {
|
|
||||||
#[structopt(help = "The MusicBrainz URL")]
|
|
||||||
url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
enum PropertyCommand {
|
enum PropertyCommand {
|
||||||
#[structopt(about = "Add values to the property without overwriting existing values")]
|
#[structopt(about = "Add values to the property without overwriting existing values")]
|
||||||
@ -173,9 +157,6 @@ impl ArtistCommand {
|
|||||||
ArtistCommand::Sort(sort_command) => {
|
ArtistCommand::Sort(sort_command) => {
|
||||||
sort_command.handle(music_hoard, artist_name);
|
sort_command.handle(music_hoard, artist_name);
|
||||||
}
|
}
|
||||||
ArtistCommand::MusicBrainz(musicbrainz_command) => {
|
|
||||||
musicbrainz_command.handle(music_hoard, artist_name)
|
|
||||||
}
|
|
||||||
ArtistCommand::Property(property_command) => {
|
ArtistCommand::Property(property_command) => {
|
||||||
property_command.handle(music_hoard, artist_name);
|
property_command.handle(music_hoard, artist_name);
|
||||||
}
|
}
|
||||||
@ -202,19 +183,6 @@ impl SortCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MusicBrainzCommand {
|
|
||||||
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
|
||||||
match self {
|
|
||||||
MusicBrainzCommand::Set(musicbrainz_value) => music_hoard
|
|
||||||
.set_artist_musicbrainz_from_url(ArtistId::new(artist_name), musicbrainz_value.url)
|
|
||||||
.expect("failed to set MusicBrainz URL"),
|
|
||||||
MusicBrainzCommand::Clear => music_hoard
|
|
||||||
.clear_artist_musicbrainz(ArtistId::new(artist_name))
|
|
||||||
.expect("failed to clear MusicBrainz URL"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropertyCommand {
|
impl PropertyCommand {
|
||||||
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
|
||||||
match self {
|
match self {
|
||||||
|
@ -33,11 +33,6 @@ pub trait IMusicHoardDatabase {
|
|||||||
artist_id: Id,
|
artist_id: Id,
|
||||||
mbid: MbRefOption<MbArtistRef>,
|
mbid: MbRefOption<MbArtistRef>,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
fn set_artist_musicbrainz_from_url<Id: AsRef<ArtistId>, S: AsRef<str>>(
|
|
||||||
&mut self,
|
|
||||||
artist_id: Id,
|
|
||||||
url: S,
|
|
||||||
) -> Result<(), Error>;
|
|
||||||
fn clear_artist_musicbrainz<Id: AsRef<ArtistId>>(&mut self, artist_id: Id)
|
fn clear_artist_musicbrainz<Id: AsRef<ArtistId>>(&mut self, artist_id: Id)
|
||||||
-> Result<(), Error>;
|
-> Result<(), Error>;
|
||||||
|
|
||||||
@ -174,17 +169,6 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_artist_musicbrainz_from_url<Id: AsRef<ArtistId>, S: AsRef<str>>(
|
|
||||||
&mut self,
|
|
||||||
artist_id: Id,
|
|
||||||
url: S,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let mb = MbArtistRef::from_url_str(url)?;
|
|
||||||
self.update_artist(artist_id.as_ref(), |artist| {
|
|
||||||
artist.meta.set_musicbrainz_ref(MbRefOption::Some(mb))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_artist_musicbrainz<Id: AsRef<ArtistId>>(
|
fn clear_artist_musicbrainz<Id: AsRef<ArtistId>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
artist_id: Id,
|
artist_id: Id,
|
||||||
@ -434,8 +418,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
static MUSICBRAINZ: &str =
|
static MBID: &str = "d368baa8-21ca-4759-9731-0b2753071ad8";
|
||||||
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";
|
|
||||||
static MUSICBUTLER: &str = "https://www.musicbutler.io/artist-page/483340948";
|
static MUSICBUTLER: &str = "https://www.musicbutler.io/artist-page/483340948";
|
||||||
static MUSICBUTLER_2: &str = "https://www.musicbutler.io/artist-page/658903042/";
|
static MUSICBUTLER_2: &str = "https://www.musicbutler.io/artist-page/658903042/";
|
||||||
|
|
||||||
@ -537,26 +520,6 @@ mod tests {
|
|||||||
assert_eq!(artist_2, &music_hoard.collection[0]);
|
assert_eq!(artist_2, &music_hoard.collection[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn collection_error() {
|
|
||||||
let mut database = MockIDatabase::new();
|
|
||||||
database.expect_load().times(1).returning(|| Ok(vec![]));
|
|
||||||
database.expect_save().times(1).returning(|_| Ok(()));
|
|
||||||
|
|
||||||
let artist_id = ArtistId::new("an artist");
|
|
||||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
|
||||||
assert!(music_hoard.add_artist(artist_id.clone()).is_ok());
|
|
||||||
|
|
||||||
let actual_err = music_hoard
|
|
||||||
.set_artist_musicbrainz_from_url(&artist_id, MUSICBUTLER)
|
|
||||||
.unwrap_err();
|
|
||||||
let expected_err = Error::CollectionError(format!(
|
|
||||||
"an error occurred when processing a URL: invalid artist MusicBrainz URL: {MUSICBUTLER}"
|
|
||||||
));
|
|
||||||
assert_eq!(actual_err, expected_err);
|
|
||||||
assert_eq!(actual_err.to_string(), expected_err.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_clear_musicbrainz_url() {
|
fn set_clear_musicbrainz_url() {
|
||||||
let mut database = MockIDatabase::new();
|
let mut database = MockIDatabase::new();
|
||||||
@ -572,17 +535,19 @@ mod tests {
|
|||||||
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
|
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
|
||||||
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
|
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
|
||||||
|
|
||||||
|
let mbref = MbRefOption::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
|
||||||
|
|
||||||
// Setting a URL on an artist not in the collection is an error.
|
// Setting a URL on an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.set_artist_musicbrainz_from_url(&artist_id_2, MUSICBRAINZ)
|
.set_artist_musicbrainz(&artist_id_2, mbref.clone())
|
||||||
.is_err());
|
.is_err());
|
||||||
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
|
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
|
||||||
|
|
||||||
// Setting a URL on an artist.
|
// Setting a URL on an artist.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.set_artist_musicbrainz_from_url(&artist_id, MUSICBRAINZ)
|
.set_artist_musicbrainz(&artist_id, mbref.clone())
|
||||||
.is_ok());
|
.is_ok());
|
||||||
expected.replace(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap());
|
expected.replace(MbArtistRef::from_uuid_str(MBID).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
|
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
|
||||||
|
|
||||||
// Clearing URLs on an artist that does not exist is an error.
|
// Clearing URLs on an artist that does not exist is an error.
|
||||||
|
Loading…
Reference in New Issue
Block a user