diff --git a/src/bin/mh-edit.rs b/src/bin/mh-edit.rs index 60d9bcc..205fb13 100644 --- a/src/bin/mh-edit.rs +++ b/src/bin/mh-edit.rs @@ -95,6 +95,18 @@ macro_rules! url_command_dispatch { }; } +macro_rules! single_url_command_dispatch { + ($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident) => { + url_command_dispatch!($cmd, $mh, $add, $remove, $set, $clear, url) + }; +} + +macro_rules! multi_url_command_dispatch { + ($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident) => { + url_command_dispatch!($cmd, $mh, $add, $remove, $set, $clear, urls) + }; +} + impl ArtistCommand { fn handle(self, music_hoard: &mut MH) { match self { @@ -108,41 +120,37 @@ impl ArtistCommand { .delete_artist(ArtistId::new(artist_value.artist)) .expect("failed to delete artist"); } - ArtistCommand::MusicBrainz(url_command) => url_command_dispatch!( + ArtistCommand::MusicBrainz(url_command) => single_url_command_dispatch!( url_command, music_hoard, add_musicbrainz_url, remove_musicbrainz_url, set_musicbrainz_url, - clear_musicbrainz_url, - url + clear_musicbrainz_url ), - ArtistCommand::MusicButler(url_command) => url_command_dispatch!( + ArtistCommand::MusicButler(url_command) => multi_url_command_dispatch!( url_command, music_hoard, add_musicbutler_urls, remove_musicbutler_urls, set_musicbutler_urls, - clear_musicbutler_urls, - urls + clear_musicbutler_urls ), - ArtistCommand::Bandcamp(url_command) => url_command_dispatch!( + ArtistCommand::Bandcamp(url_command) => multi_url_command_dispatch!( url_command, music_hoard, add_bandcamp_urls, remove_bandcamp_urls, set_bandcamp_urls, - clear_bandcamp_urls, - urls + clear_bandcamp_urls ), - ArtistCommand::Qobuz(url_command) => url_command_dispatch!( + ArtistCommand::Qobuz(url_command) => single_url_command_dispatch!( url_command, music_hoard, add_qobuz_url, remove_qobuz_url, set_qobuz_url, - clear_qobuz_url, - url + clear_qobuz_url ), } }