From bd73e30cdf36991ddd669b496ca2274d904e5ea5 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Sat, 22 Jun 2024 17:25:33 -0400 Subject: [PATCH] #45: Add command for testing wikitext --- src/cli.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index 96aeeb44..25173bd8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -89,6 +89,14 @@ pub enum Subcommand { Duplicates, /// List games with irregular paths. Irregular, + /// Try parsing a file containing wikitext. + /// If there are parsing errors, print them and exit with 1; + /// otherwise, print nothing and exit with 0. + Wikitext { + /// Path to file containing wikitext. + #[clap(default_value_t = format!("{}/tmp/wiki.txt", crate::REPO))] + path: String, + }, } pub fn parse() -> Cli { @@ -197,6 +205,24 @@ pub async fn run( } } } + Subcommand::Wikitext { path } => { + let Ok(content) = std::fs::read_to_string(&path) else { + eprintln!("Unable to read file: {path}"); + std::process::exit(2); + }; + + let mut malformed = false; + wikitext_parser::parse_wikitext(&content, "Test".to_string(), |e| { + malformed = true; + dbg!(e); + }); + + if malformed { + std::process::exit(1); + } else { + std::process::exit(0); + } + } } Ok(())