(e6e3a1b) Guard the README command table against a missing row
The campaign and assign rows landed with 528566d. What was left was the
checking, done here against the built binary rather than against the
ticket that added them.
The campaign ls row was incomplete: the listing also prints the derived
state, [open] until every member is done and [done] after, and reads
"no members" with no state for a campaign nothing has been filed
against, which is neither. Corrected.
every_subcommand_has_a_row_in_the_readme_command_table walks clap's own
subcommands, one level of nesting included, against the table's rows.
Two commands hid behind an otherwise complete table for two minor
versions because the only thing walking it was somebody remembering to.
The tag subcommands are named in a PENDING list rather than skipped,
since f7dd1a1 rewrites that row.
This commit is contained in:
@@ -881,3 +881,68 @@ pub struct CheckArgs {
|
||||
/// Criterion indexes as shown by `show`, substrings of their text, or `all`. Prompts if omitted
|
||||
pub criteria: Vec<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use clap::CommandFactory;
|
||||
|
||||
/// The command names as the README table would have to spell them: `campaign add`
|
||||
/// for a nested one, the bare name for a top level one. `help` is clap's own and
|
||||
/// documents nothing.
|
||||
fn documented_names() -> Vec<String> {
|
||||
let cli = Cli::command();
|
||||
let mut names = Vec::new();
|
||||
|
||||
for sub in cli.get_subcommands() {
|
||||
if sub.get_name() == "help" {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.push(sub.get_name().to_string());
|
||||
for nested in sub.get_subcommands() {
|
||||
if nested.get_name() == "help" {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.push(format!("{} {}", sub.get_name(), nested.get_name()));
|
||||
}
|
||||
}
|
||||
|
||||
names
|
||||
}
|
||||
|
||||
/// Every subcommand has a row in the README's command table.
|
||||
///
|
||||
/// `campaign` and `assign` went undocumented for two minor versions, e6e3a1b, and
|
||||
/// the `--campaign` flag went with them, because the only thing walking the table
|
||||
/// was somebody remembering to. This is what walks it. A command whose row is
|
||||
/// missing is a command a reader of the README cannot discover at all, which is a
|
||||
/// worse failure than a row that is merely out of date.
|
||||
#[test]
|
||||
fn every_subcommand_has_a_row_in_the_readme_command_table() {
|
||||
// The tag subcommands are f7dd1a1's, which rewrites the `worklane tags` row
|
||||
// once the vocabulary work above it has landed. Listed rather than skipped, so
|
||||
// emptying this is part of closing that ticket rather than something to
|
||||
// rediscover.
|
||||
const PENDING: [&str; 3] = ["tags add", "tags set", "tags ls"];
|
||||
|
||||
let readme = include_str!("../README.md");
|
||||
let table: String = readme.lines().filter(|line| line.starts_with('|')).collect();
|
||||
|
||||
let missing: Vec<String> = documented_names()
|
||||
.into_iter()
|
||||
.filter(|name| !PENDING.contains(&name.as_str()))
|
||||
.filter(|name| !table.contains(&format!("`worklane {}", name)))
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
missing.is_empty(),
|
||||
"no row in the README command table for {missing:?}. A new command is not \
|
||||
shipped until the table lists it: that table is the only place a reader \
|
||||
discovers one, and two commands hid behind an otherwise complete table \
|
||||
for two minor versions."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user