Add discovery subcommands list and fields
Some checks failed
CI / Typos (push) Failing after 17s
CI / Build and test (push) Failing after 2m13s
CI / Clippy (push) Failing after 3m33s
CI / Build and test (all features) (push) Failing after 6m8s

This commit is contained in:
2026-03-10 21:50:09 -07:00
parent bfa67994bf
commit adcf46314f
8 changed files with 437 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
use pile_config::Label;
use std::{collections::HashMap, sync::Arc};
use std::sync::Arc;
mod epub_meta;
pub use epub_meta::*;
@@ -7,39 +7,30 @@ pub use epub_meta::*;
mod epub_text;
pub use epub_text::*;
use crate::{
Item, PileValue,
extract::{MapExtractor, ObjectExtractor},
};
use crate::{Item, PileValue, extract::ObjectExtractor};
pub struct EpubExtractor {
inner: MapExtractor,
text: Arc<EpubTextExtractor>,
meta: Arc<EpubMetaExtractor>,
}
impl EpubExtractor {
#[expect(clippy::unwrap_used)]
pub fn new(item: &Item) -> Self {
let inner = MapExtractor {
inner: HashMap::from([
(
Label::new("text").unwrap(),
PileValue::ObjectExtractor(Arc::new(EpubTextExtractor::new(item))),
),
(
Label::new("meta").unwrap(),
PileValue::ObjectExtractor(Arc::new(EpubMetaExtractor::new(item))),
),
]),
};
Self { inner }
Self {
text: Arc::new(EpubTextExtractor::new(item)),
meta: Arc::new(EpubMetaExtractor::new(item)),
}
}
}
#[async_trait::async_trait]
impl ObjectExtractor for EpubExtractor {
async fn field(&self, name: &pile_config::Label) -> Result<Option<PileValue>, std::io::Error> {
self.inner.field(name).await
match name.as_str() {
"text" => self.text.field(name).await,
"meta" => Ok(Some(PileValue::ObjectExtractor(self.meta.clone()))),
_ => Ok(None),
}
}
#[expect(clippy::unwrap_used)]