use clap::{builder::PossibleValue, Args, ValueEnum};
use dynasty_api::{
directory::DirectoryKind,
search::{SearchCategory, SearchSort},
};
#[derive(Debug, Clone, Args)]
pub struct SearchCommand {
pub query: Option<String>,
#[arg(short, long)]
pub sort: Option<SearchValueSort>,
#[arg(short, long)]
pub categories: Vec<SearchValueCategory>,
}
#[derive(Debug, Clone, Copy)]
pub struct SearchValueSort(pub SearchSort);
impl ValueEnum for SearchValueSort {
fn value_variants<'a>() -> &'a [Self] {
use SearchSort::*;
&[
Self(Alphabetical),
Self(BestMatch),
Self(DateAdded),
Self(ReleaseDate),
]
}
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
use SearchSort::*;
Some(match &self.0 {
Alphabetical => PossibleValue::new("alphabetical"),
BestMatch => PossibleValue::new("best-match"),
DateAdded => PossibleValue::new("date-added"),
ReleaseDate => PossibleValue::new("release-date"),
})
}
}
#[derive(Debug, Clone, Copy)]
pub struct SearchValueCategory(pub SearchCategory);
impl ValueEnum for SearchValueCategory {
fn value_variants<'a>() -> &'a [Self] {
use DirectoryKind::*;
use SearchCategory::*;
&[
Self(Chapter),
Self(Directory(Anthology)),
Self(Directory(Author)),
Self(Directory(Doujin)),
Self(Directory(Tag)),
Self(Directory(Issue)),
Self(Directory(Pairing)),
Self(Directory(Scanlator)),
Self(Directory(Series)),
]
}
fn to_possible_value(&self) -> Option<PossibleValue> {
Some(match &self.0 {
SearchCategory::Chapter => PossibleValue::new("chapter"),
SearchCategory::Directory(kind) => {
use DirectoryKind::*;
match kind {
Anthology => PossibleValue::new("anthology"),
Doujin => PossibleValue::new("doujin"),
Issue => PossibleValue::new("issue"),
Series => PossibleValue::new("series"),
Author => PossibleValue::new("author"),
Scanlator => PossibleValue::new("scanlator"),
Tag => PossibleValue::new("tag"),
Pairing => PossibleValue::new("pairing"),
}
}
})
}
}