mirror of
https://github.com/0xMassi/webclaw.git
synced 2026-05-13 17:02:36 +02:00
feat: derive Deserialize on OutputFormat, Browser, PdfModeArg
This commit is contained in:
parent
af304eda7f
commit
cfe455b752
2 changed files with 33 additions and 3 deletions
|
|
@ -17,6 +17,7 @@ noxa-pdf = { workspace = true }
|
||||||
dotenvy = { workspace = true }
|
dotenvy = { workspace = true }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
|
use serde::Deserialize;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
use noxa_core::{
|
use noxa_core::{
|
||||||
ChangeStatus, ContentDiff, ExtractionOptions, ExtractionResult, Metadata, extract_with_options,
|
ChangeStatus, ContentDiff, ExtractionOptions, ExtractionResult, Metadata, extract_with_options,
|
||||||
|
|
@ -284,7 +285,8 @@ struct Cli {
|
||||||
output_dir: Option<PathBuf>,
|
output_dir: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ValueEnum)]
|
#[derive(Clone, ValueEnum, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
enum OutputFormat {
|
enum OutputFormat {
|
||||||
Markdown,
|
Markdown,
|
||||||
Json,
|
Json,
|
||||||
|
|
@ -293,14 +295,16 @@ enum OutputFormat {
|
||||||
Html,
|
Html,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ValueEnum)]
|
#[derive(Clone, ValueEnum, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
enum Browser {
|
enum Browser {
|
||||||
Chrome,
|
Chrome,
|
||||||
Firefox,
|
Firefox,
|
||||||
Random,
|
Random,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ValueEnum, Default)]
|
#[derive(Clone, ValueEnum, Default, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
enum PdfModeArg {
|
enum PdfModeArg {
|
||||||
/// Error if PDF has no extractable text (catches scanned PDFs)
|
/// Error if PDF has no extractable text (catches scanned PDFs)
|
||||||
#[default]
|
#[default]
|
||||||
|
|
@ -2467,3 +2471,28 @@ mod tests {
|
||||||
let _ = std::fs::remove_dir_all(&dir);
|
let _ = std::fs::remove_dir_all(&dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod enum_deserialize_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_output_format_deserialize() {
|
||||||
|
let f: OutputFormat = serde_json::from_str("\"llm\"").unwrap();
|
||||||
|
assert!(matches!(f, OutputFormat::Llm));
|
||||||
|
let f: OutputFormat = serde_json::from_str("\"markdown\"").unwrap();
|
||||||
|
assert!(matches!(f, OutputFormat::Markdown));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_browser_deserialize() {
|
||||||
|
let b: Browser = serde_json::from_str("\"firefox\"").unwrap();
|
||||||
|
assert!(matches!(b, Browser::Firefox));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_pdf_mode_deserialize() {
|
||||||
|
let p: PdfModeArg = serde_json::from_str("\"fast\"").unwrap();
|
||||||
|
assert!(matches!(p, PdfModeArg::Fast));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue