use clap::CommandFactory;
const REFERENCE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/docs/cli-reference.md"
));
const REQUIRED_FLAGS: &[&str] = &[
"--limit",
"--cursor",
"--watch",
"--poll-ms",
"--by", "--integration-ref",
"--worktree", "--responds-to",
"--confidence", ];
fn collect_leaf_paths(cmd: &clap::Command, prefix: &mut Vec<String>, out: &mut Vec<String>) {
let subs: Vec<&clap::Command> = cmd
.get_subcommands()
.filter(|c| c.get_name() != "help")
.collect();
if subs.is_empty() {
if !prefix.is_empty() {
out.push(prefix.join(" "));
}
return;
}
for sub in subs {
prefix.push(sub.get_name().to_owned());
collect_leaf_paths(sub, prefix, out);
prefix.pop();
}
}
#[test]
fn every_leaf_command_is_documented() {
let cmd = super::Cli::command();
let mut paths = Vec::new();
collect_leaf_paths(&cmd, &mut Vec::new(), &mut paths);
let missing: Vec<String> = paths
.iter()
.filter(|path| !REFERENCE.contains(&format!("shore {path}")))
.cloned()
.collect();
assert!(
missing.is_empty(),
"commands missing from docs/cli-reference.md:\n{}",
missing.join("\n")
);
}
#[test]
fn collect_leaf_paths_walks_hidden_leaves() {
let hidden_leaf = clap::Command::new("legacy").hide(true);
let root = clap::Command::new("shore").subcommand(hidden_leaf);
let mut paths = Vec::new();
collect_leaf_paths(&root, &mut Vec::new(), &mut paths);
assert!(
paths.contains(&"legacy".to_owned()),
"hidden leaves must still be walked so reference_coverage.rs keeps documenting them: {paths:?}"
);
}
#[test]
fn audit_flags_are_documented() {
let missing: Vec<&str> = REQUIRED_FLAGS
.iter()
.copied()
.filter(|flag| !REFERENCE.contains(flag))
.collect();
assert!(
missing.is_empty(),
"flags missing from docs/cli-reference.md: {missing:?}"
);
}