Auto-generate the method identifiers
This commit is contained in:
parent
d0e04d8a78
commit
f36247f53b
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -369,6 +369,7 @@ dependencies = [
|
|||||||
"mockall",
|
"mockall",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"openssh",
|
"openssh",
|
||||||
|
"paste",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -456,6 +457,12 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
@ -8,6 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = { version = "0.26.1", optional = true}
|
crossterm = { version = "0.26.1", optional = true}
|
||||||
openssh = { version = "0.9.9", features = ["native-mux"], default-features = false, optional = true}
|
openssh = { version = "0.9.9", features = ["native-mux"], default-features = false, optional = true}
|
||||||
|
paste = { version = "1.0.14" }
|
||||||
ratatui = { version = "0.20.1", optional = true}
|
ratatui = { version = "0.20.1", optional = true}
|
||||||
serde = { version = "1.0.159", features = ["derive"] }
|
serde = { version = "1.0.159", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.95", optional = true}
|
serde_json = { version = "1.0.95", optional = true}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use paste::paste;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
@ -73,37 +74,39 @@ struct MultiUrlValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! url_command_dispatch {
|
macro_rules! url_command_dispatch {
|
||||||
($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident, $url:ident) => {
|
($cmd:ident, $mh:ident, $field:ident, $url:ident) => {
|
||||||
match $cmd {
|
paste! {
|
||||||
UrlCommand::Add(url_value) => {
|
match $cmd {
|
||||||
$mh.$add(ArtistId::new(url_value.artist), url_value.$url)
|
UrlCommand::Add(url_value) => {
|
||||||
.expect("failed to add URL(s)");
|
$mh.[<add_ $field _ $url>](ArtistId::new(url_value.artist), url_value.$url)
|
||||||
}
|
.expect("failed to add URL(s)");
|
||||||
UrlCommand::Remove(url_value) => {
|
}
|
||||||
$mh.$remove(ArtistId::new(url_value.artist), url_value.$url)
|
UrlCommand::Remove(url_value) => {
|
||||||
.expect("failed to remove URL(s)");
|
$mh.[<remove_ $field _ $url>](ArtistId::new(url_value.artist), url_value.$url)
|
||||||
}
|
.expect("failed to remove URL(s)");
|
||||||
UrlCommand::Set(url_value) => {
|
}
|
||||||
$mh.$set(ArtistId::new(url_value.artist), url_value.$url)
|
UrlCommand::Set(url_value) => {
|
||||||
.expect("failed to set URL(s)");
|
$mh.[<set_ $field _ $url>](ArtistId::new(url_value.artist), url_value.$url)
|
||||||
}
|
.expect("failed to set URL(s)");
|
||||||
UrlCommand::Clear(artist_value) => {
|
}
|
||||||
$mh.$clear(ArtistId::new(artist_value.artist))
|
UrlCommand::Clear(artist_value) => {
|
||||||
.expect("failed to clear URL(s)");
|
$mh.[<clear_ $field _ $url>](ArtistId::new(artist_value.artist))
|
||||||
|
.expect("failed to clear URL(s)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! single_url_command_dispatch {
|
macro_rules! single_url_command_dispatch {
|
||||||
($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident) => {
|
($cmd:ident, $mh:ident, $field:ident) => {
|
||||||
url_command_dispatch!($cmd, $mh, $add, $remove, $set, $clear, url)
|
url_command_dispatch!($cmd, $mh, $field, url)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! multi_url_command_dispatch {
|
macro_rules! multi_url_command_dispatch {
|
||||||
($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident) => {
|
($cmd:ident, $mh:ident, $field:ident) => {
|
||||||
url_command_dispatch!($cmd, $mh, $add, $remove, $set, $clear, urls)
|
url_command_dispatch!($cmd, $mh, $field, urls)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,38 +123,18 @@ impl ArtistCommand {
|
|||||||
.delete_artist(ArtistId::new(artist_value.artist))
|
.delete_artist(ArtistId::new(artist_value.artist))
|
||||||
.expect("failed to delete artist");
|
.expect("failed to delete artist");
|
||||||
}
|
}
|
||||||
ArtistCommand::MusicBrainz(url_command) => single_url_command_dispatch!(
|
ArtistCommand::MusicBrainz(url_command) => {
|
||||||
url_command,
|
single_url_command_dispatch!(url_command, music_hoard, musicbrainz)
|
||||||
music_hoard,
|
}
|
||||||
add_musicbrainz_url,
|
ArtistCommand::MusicButler(url_command) => {
|
||||||
remove_musicbrainz_url,
|
multi_url_command_dispatch!(url_command, music_hoard, musicbutler)
|
||||||
set_musicbrainz_url,
|
}
|
||||||
clear_musicbrainz_url
|
ArtistCommand::Bandcamp(url_command) => {
|
||||||
),
|
multi_url_command_dispatch!(url_command, music_hoard, bandcamp)
|
||||||
ArtistCommand::MusicButler(url_command) => multi_url_command_dispatch!(
|
}
|
||||||
url_command,
|
ArtistCommand::Qobuz(url_command) => {
|
||||||
music_hoard,
|
single_url_command_dispatch!(url_command, music_hoard, qobuz)
|
||||||
add_musicbutler_urls,
|
}
|
||||||
remove_musicbutler_urls,
|
|
||||||
set_musicbutler_urls,
|
|
||||||
clear_musicbutler_urls
|
|
||||||
),
|
|
||||||
ArtistCommand::Bandcamp(url_command) => multi_url_command_dispatch!(
|
|
||||||
url_command,
|
|
||||||
music_hoard,
|
|
||||||
add_bandcamp_urls,
|
|
||||||
remove_bandcamp_urls,
|
|
||||||
set_bandcamp_urls,
|
|
||||||
clear_bandcamp_urls
|
|
||||||
),
|
|
||||||
ArtistCommand::Qobuz(url_command) => single_url_command_dispatch!(
|
|
||||||
url_command,
|
|
||||||
music_hoard,
|
|
||||||
add_qobuz_url,
|
|
||||||
remove_qobuz_url,
|
|
||||||
set_qobuz_url,
|
|
||||||
clear_qobuz_url
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
222
src/lib.rs
222
src/lib.rs
@ -13,6 +13,7 @@ use std::{
|
|||||||
|
|
||||||
use database::IDatabase;
|
use database::IDatabase;
|
||||||
use library::{ILibrary, Item, Query};
|
use library::{ILibrary, Item, Query};
|
||||||
|
use paste::paste;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@ -378,41 +379,45 @@ pub struct Artist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! artist_unique_url_dispatch {
|
macro_rules! artist_unique_url_dispatch {
|
||||||
($add:ident, $remove:ident, $set:ident, $clear:ident, $field:ident) => {
|
($field:ident) => {
|
||||||
fn $add<S: AsRef<str>>(&mut self, url: S) -> Result<(), Error> {
|
paste! {
|
||||||
Self::add_unique_url(&mut self.properties.$field, url)
|
fn [<add_ $field _url>]<S: AsRef<str>>(&mut self, url: S) -> Result<(), Error> {
|
||||||
}
|
Self::add_unique_url(&mut self.properties.$field, url)
|
||||||
|
}
|
||||||
|
|
||||||
fn $remove<S: AsRef<str>>(&mut self, url: S) -> Result<(), Error> {
|
fn [<remove_ $field _url>]<S: AsRef<str>>(&mut self, url: S) -> Result<(), Error> {
|
||||||
Self::remove_unique_url(&mut self.properties.$field, url)
|
Self::remove_unique_url(&mut self.properties.$field, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn $set<S: AsRef<str>>(&mut self, url: S) -> Result<(), Error> {
|
fn [<set_ $field _url>]<S: AsRef<str>>(&mut self, url: S) -> Result<(), Error> {
|
||||||
Self::set_unique_url(&mut self.properties.$field, url)
|
Self::set_unique_url(&mut self.properties.$field, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn $clear(&mut self) {
|
fn [<clear_ $field _url>](&mut self) {
|
||||||
Self::clear_unique_url(&mut self.properties.$field);
|
Self::clear_unique_url(&mut self.properties.$field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! artist_multi_url_dispatch {
|
macro_rules! artist_multi_url_dispatch {
|
||||||
($add:ident, $remove:ident, $set:ident, $clear:ident, $field:ident) => {
|
($field:ident) => {
|
||||||
fn $add<S: AsRef<str>>(&mut self, urls: Vec<S>) -> Result<(), Error> {
|
paste! {
|
||||||
Self::add_multi_urls(&mut self.properties.$field, urls)
|
fn [<add_ $field _urls>]<S: AsRef<str>>(&mut self, urls: Vec<S>) -> Result<(), Error> {
|
||||||
}
|
Self::add_multi_urls(&mut self.properties.$field, urls)
|
||||||
|
}
|
||||||
|
|
||||||
fn $remove<S: AsRef<str>>(&mut self, urls: Vec<S>) -> Result<(), Error> {
|
fn [<remove_ $field _urls>]<S: AsRef<str>>(&mut self, urls: Vec<S>) -> Result<(), Error> {
|
||||||
Self::remove_multi_urls(&mut self.properties.$field, urls)
|
Self::remove_multi_urls(&mut self.properties.$field, urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn $set<S: AsRef<str>>(&mut self, urls: Vec<S>) -> Result<(), Error> {
|
fn [<set_ $field _urls>]<S: AsRef<str>>(&mut self, urls: Vec<S>) -> Result<(), Error> {
|
||||||
Self::set_multi_urls(&mut self.properties.$field, urls)
|
Self::set_multi_urls(&mut self.properties.$field, urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn $clear(&mut self) {
|
fn [<clear_ $field _urls>](&mut self) {
|
||||||
Self::clear_multi_urls(&mut self.properties.$field);
|
Self::clear_multi_urls(&mut self.properties.$field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -526,37 +531,13 @@ impl Artist {
|
|||||||
container.clear();
|
container.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
artist_unique_url_dispatch!(
|
artist_unique_url_dispatch!(musicbrainz);
|
||||||
add_musicbrainz_url,
|
|
||||||
remove_musicbrainz_url,
|
|
||||||
set_musicbrainz_url,
|
|
||||||
clear_musicbrainz_url,
|
|
||||||
musicbrainz
|
|
||||||
);
|
|
||||||
|
|
||||||
artist_multi_url_dispatch!(
|
artist_multi_url_dispatch!(musicbutler);
|
||||||
add_musicbutler_urls,
|
|
||||||
remove_musicbutler_urls,
|
|
||||||
set_musicbutler_urls,
|
|
||||||
clear_musicbutler_urls,
|
|
||||||
musicbutler
|
|
||||||
);
|
|
||||||
|
|
||||||
artist_multi_url_dispatch!(
|
artist_multi_url_dispatch!(bandcamp);
|
||||||
add_bandcamp_urls,
|
|
||||||
remove_bandcamp_urls,
|
|
||||||
set_bandcamp_urls,
|
|
||||||
clear_bandcamp_urls,
|
|
||||||
bandcamp
|
|
||||||
);
|
|
||||||
|
|
||||||
artist_unique_url_dispatch!(
|
artist_unique_url_dispatch!(qobuz);
|
||||||
add_qobuz_url,
|
|
||||||
remove_qobuz_url,
|
|
||||||
set_qobuz_url,
|
|
||||||
clear_qobuz_url,
|
|
||||||
qobuz
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialOrd for Artist {
|
impl PartialOrd for Artist {
|
||||||
@ -721,67 +702,76 @@ pub struct MusicHoard<LIB, DB> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! music_hoard_unique_url_dispatch {
|
macro_rules! music_hoard_unique_url_dispatch {
|
||||||
($add:ident, $remove:ident, $set:ident, $clear:ident) => {
|
($field:ident) => {
|
||||||
pub fn $add<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
paste! {
|
||||||
&mut self,
|
pub fn [<add_ $field _url>]<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
artist_id: ID,
|
&mut self,
|
||||||
url: S,
|
artist_id: ID,
|
||||||
) -> Result<(), Error> {
|
url: S,
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$add(url)
|
) -> Result<(), Error> {
|
||||||
}
|
self.get_artist_or_err(artist_id.as_ref())?.[<add_ $field _url>](url)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn $remove<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
pub fn [<remove_ $field _url>]<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
artist_id: ID,
|
artist_id: ID,
|
||||||
url: S,
|
url: S,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$remove(url)
|
self.get_artist_or_err(artist_id.as_ref())?.[<remove_ $field _url>](url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn $set<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
pub fn [<set_ $field _url>]<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
artist_id: ID,
|
artist_id: ID,
|
||||||
url: S,
|
url: S,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$set(url)
|
self.get_artist_or_err(artist_id.as_ref())?.[<set_ $field _url>](url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn $clear<ID: AsRef<ArtistId>>(&mut self, artist_id: ID) -> Result<(), Error> {
|
pub fn [<clear_ $field _url>]<ID: AsRef<ArtistId>>(
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$clear();
|
&mut self,
|
||||||
Ok(())
|
artist_id: ID,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
self.get_artist_or_err(artist_id.as_ref())?.[<clear_ $field _url>]();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! music_hoard_multi_url_dispatch {
|
macro_rules! music_hoard_multi_url_dispatch {
|
||||||
($add:ident, $remove:ident, $set:ident, $clear:ident) => {
|
($field:ident) => {
|
||||||
pub fn $add<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
paste! {
|
||||||
&mut self,
|
pub fn [<add_ $field _urls>]<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
artist_id: ID,
|
&mut self,
|
||||||
urls: Vec<S>,
|
artist_id: ID,
|
||||||
) -> Result<(), Error> {
|
urls: Vec<S>,
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$add(urls)
|
) -> Result<(), Error> {
|
||||||
}
|
self.get_artist_or_err(artist_id.as_ref())?.[<add_ $field _urls>](urls)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn $remove<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
pub fn [<remove_ $field _urls>]<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
artist_id: ID,
|
artist_id: ID,
|
||||||
urls: Vec<S>,
|
urls: Vec<S>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$remove(urls)
|
self.get_artist_or_err(artist_id.as_ref())?.[<remove_ $field _urls>](urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn $set<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
pub fn [<set_ $field _urls>]<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
artist_id: ID,
|
artist_id: ID,
|
||||||
urls: Vec<S>,
|
urls: Vec<S>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$set(urls)
|
self.get_artist_or_err(artist_id.as_ref())?.[<set_ $field _urls>](urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn $clear<ID: AsRef<ArtistId>>(&mut self, artist_id: ID) -> Result<(), Error> {
|
pub fn [<clear_ $field _urls>]<ID: AsRef<ArtistId>>(
|
||||||
self.get_artist_or_err(artist_id.as_ref())?.$clear();
|
&mut self, artist_id: ID,
|
||||||
Ok(())
|
) -> Result<(), Error> {
|
||||||
|
self.get_artist_or_err(artist_id.as_ref())?.[<clear_ $field _urls>]();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -876,33 +866,13 @@ impl<LIB: ILibrary, DB: IDatabase> MusicHoard<LIB, DB> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
music_hoard_unique_url_dispatch!(
|
music_hoard_unique_url_dispatch!(musicbrainz);
|
||||||
add_musicbrainz_url,
|
|
||||||
remove_musicbrainz_url,
|
|
||||||
set_musicbrainz_url,
|
|
||||||
clear_musicbrainz_url
|
|
||||||
);
|
|
||||||
|
|
||||||
music_hoard_multi_url_dispatch!(
|
music_hoard_multi_url_dispatch!(musicbutler);
|
||||||
add_musicbutler_urls,
|
|
||||||
remove_musicbutler_urls,
|
|
||||||
set_musicbutler_urls,
|
|
||||||
clear_musicbutler_urls
|
|
||||||
);
|
|
||||||
|
|
||||||
music_hoard_multi_url_dispatch!(
|
music_hoard_multi_url_dispatch!(bandcamp);
|
||||||
add_bandcamp_urls,
|
|
||||||
remove_bandcamp_urls,
|
|
||||||
set_bandcamp_urls,
|
|
||||||
clear_bandcamp_urls
|
|
||||||
);
|
|
||||||
|
|
||||||
music_hoard_unique_url_dispatch!(
|
music_hoard_unique_url_dispatch!(qobuz);
|
||||||
add_qobuz_url,
|
|
||||||
remove_qobuz_url,
|
|
||||||
set_qobuz_url,
|
|
||||||
clear_qobuz_url
|
|
||||||
);
|
|
||||||
|
|
||||||
fn sort(collection: &mut [Artist]) {
|
fn sort(collection: &mut [Artist]) {
|
||||||
collection.sort_unstable();
|
collection.sort_unstable();
|
||||||
|
Loading…
Reference in New Issue
Block a user