#45: Add command for testing wikitext
This commit is contained in:
parent
6676218ee7
commit
bd73e30cdf
1 changed files with 26 additions and 0 deletions
26
src/cli.rs
26
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(())
|
||||
|
|
Reference in a new issue