use clap::CommandFactory;
const RETIRED_VOCAB_TOKENS: &[&str] = &[
"unit",
"units",
"engagement",
"engagements",
"workobjectproposed",
"taskattempt",
];
fn has_retired_vocab_token(text: &str) -> bool {
text.to_lowercase()
.split(|c: char| !c.is_ascii_alphanumeric())
.any(|token| RETIRED_VOCAB_TOKENS.contains(&token))
}
fn collect_help_text(cmd: &clap::Command, out: &mut Vec<(String, String)>) {
let name = cmd.get_name().to_owned();
if let Some(about) = cmd.get_about() {
out.push((name.clone(), about.to_string()));
}
if let Some(long) = cmd.get_long_about() {
out.push((name.clone(), long.to_string()));
}
for arg in cmd.get_arguments() {
if let Some(help) = arg.get_help() {
out.push((format!("{name} --{}", arg.get_id()), help.to_string()));
}
if let Some(help) = arg.get_long_help() {
out.push((format!("{name} --{}", arg.get_id()), help.to_string()));
}
}
for sub in cmd.get_subcommands() {
collect_help_text(sub, out);
}
}
#[test]
fn help_text_is_free_of_retired_vocabulary() {
let cmd = super::Cli::command();
let mut texts = Vec::new();
collect_help_text(&cmd, &mut texts);
let offenders: Vec<String> = texts
.iter()
.filter(|(_, text)| has_retired_vocab_token(text))
.map(|(where_, text)| format!("{where_}: {text}"))
.collect();
assert!(
offenders.is_empty(),
"retired review-unit vocabulary (unit/units token) in clap help/about text:\n{}",
offenders.join("\n")
);
}