Remove some unneeded functionality
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 1m47s
Cargo CI / Lint (pull_request) Successful in 1m10s

This commit is contained in:
Wojciech Kozlowski 2024-09-28 09:18:39 +02:00
parent c6424ec036
commit 735cd00ab7
2 changed files with 6 additions and 73 deletions

View File

@ -51,8 +51,6 @@ enum ArtistCommand {
Remove,
#[structopt(about = "Edit the artist's sort name")]
Sort(SortCommand),
#[structopt(name = "musicbrainz", about = "Edit the MusicBrainz URL of an artist")]
MusicBrainz(MusicBrainzCommand),
#[structopt(about = "Edit a property of an artist")]
Property(PropertyCommand),
#[structopt(about = "Modify the artist's album information")]
@ -73,20 +71,6 @@ struct SortValue {
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)]
enum PropertyCommand {
#[structopt(about = "Add values to the property without overwriting existing values")]
@ -173,9 +157,6 @@ impl ArtistCommand {
ArtistCommand::Sort(sort_command) => {
sort_command.handle(music_hoard, artist_name);
}
ArtistCommand::MusicBrainz(musicbrainz_command) => {
musicbrainz_command.handle(music_hoard, artist_name)
}
ArtistCommand::Property(property_command) => {
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 {
fn handle(self, music_hoard: &mut MH, artist_name: &str) {
match self {

View File

@ -33,11 +33,6 @@ pub trait IMusicHoardDatabase {
artist_id: Id,
mbid: MbRefOption<MbArtistRef>,
) -> 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)
-> 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>>(
&mut self,
artist_id: Id,
@ -434,8 +418,7 @@ mod tests {
use super::*;
static MUSICBRAINZ: &str =
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";
static MBID: &str = "d368baa8-21ca-4759-9731-0b2753071ad8";
static MUSICBUTLER: &str = "https://www.musicbutler.io/artist-page/483340948";
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]);
}
#[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]
fn set_clear_musicbrainz_url() {
let mut database = MockIDatabase::new();
@ -572,17 +535,19 @@ mod tests {
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
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.
assert!(music_hoard
.set_artist_musicbrainz_from_url(&artist_id_2, MUSICBRAINZ)
.set_artist_musicbrainz(&artist_id_2, mbref.clone())
.is_err());
assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
// Setting a URL on an artist.
assert!(music_hoard
.set_artist_musicbrainz_from_url(&artist_id, MUSICBRAINZ)
.set_artist_musicbrainz(&artist_id, mbref.clone())
.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);
// Clearing URLs on an artist that does not exist is an error.