#[macro_export]
macro_rules! define_inline_or_ref {
($struct_name:ident, $arg_name:literal, $output_ty:ty, $remote_variant:ident) => {
#[derive(clap::Args)]
#[group(id = concat!($arg_name, "-group"), required = true, multiple = false)]
pub struct $struct_name {
#[arg(id = $arg_name, long = $arg_name, value_name = "REFERENCE", help = concat!("Reference (e.g. favorite=name or remote=github,owner=x,repository=y)"))]
reference: Option<crate::favorite_ref::FavoriteRef>,
#[arg(id = concat!($arg_name, "-inline"), long = concat!($arg_name, "-inline"), value_name = "INLINE", help = "Inline JSON definition")]
inline: Option<String>,
}
impl $struct_name {
pub async fn resolve<F, Fut>(
self,
get_favorites: F,
) -> Result<$output_ty, crate::error::Error>
where
F: FnOnce() -> Fut,
Fut: std::future::Future<Output = Vec<objectiveai_sdk::filesystem::config::Favorite>>,
{
if let Some(json) = self.inline {
let mut de = serde_json::Deserializer::from_str(&json);
return serde_path_to_error::deserialize(&mut de)
.map_err(crate::error::Error::InlineDeserialize);
}
if let Some(fav_ref) = self.reference {
let path = fav_ref.resolve(get_favorites).await?;
return Ok(<$output_ty>::$remote_variant(path));
}
unreachable!("clap group ensures one is set")
}
}
};
}