use crate::runner::HelpOutput;
const LIST_VERBS: &[&str] = &["list", "ls", "search", "query", "find", "show", "get"];
pub(crate) fn has_list_style_subcommand(help: &HelpOutput) -> bool {
help.subcommands()
.iter()
.any(|s| LIST_VERBS.iter().any(|verb| s.eq_ignore_ascii_case(verb)))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn detects_list_verb() {
let help = HelpOutput::from_raw(
"Usage: tool [COMMAND]\n\nCommands:\n list List items.\n build Build.\n",
);
assert!(has_list_style_subcommand(&help));
}
#[test]
fn detects_search_verb() {
let help =
HelpOutput::from_raw("Usage: tool [COMMAND]\n\nCommands:\n search Search items.\n");
assert!(has_list_style_subcommand(&help));
}
#[test]
fn case_insensitive_match() {
let help =
HelpOutput::from_raw("Usage: tool [COMMAND]\n\nCommands:\n LIST UPPERCASE.\n");
assert!(has_list_style_subcommand(&help));
}
#[test]
fn rejects_non_list_verbs() {
let help = HelpOutput::from_raw(
"Usage: tool [COMMAND]\n\nCommands:\n audit Run audits.\n build Build.\n run Run.\n",
);
assert!(!has_list_style_subcommand(&help));
}
#[test]
fn empty_subcommand_list_returns_false() {
let help = HelpOutput::from_raw("Usage: tool [OPTIONS]\n\nOptions:\n -h, --help\n");
assert!(!has_list_style_subcommand(&help));
}
}