#45: Add command for testing wikitext

This commit is contained in:
mtkennerly 2024-06-22 17:25:33 -04:00
parent 6676218ee7
commit bd73e30cdf
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408

View file

@ -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(())