requirements.cli.clap
Requirements index · View definition
Requirement
The
habeasCLI MUST useclapto define and parse its commands and options.
Rationale
The requirement requirements.cli.clap has one obligation: the habeas CLI defines and parses its commands and options with clap. A black-box test can only check this through behavior that clap produces. tests/cli.rs#fn[clap_defines_commands_options_and_usage_errors] is marked {test} and runs the real binary to check that behavior.
- Command definition:
--helpsucceeds and starts withUsage: habeas <COMMAND>. It listsmdbook,setup,status,info,authorandhelpin clap’s two-space-indented format. It also asserts that the hiddenhookcommand stays out of the help, which checks that#[command(hide = true)]is honored. - Option definition:
status --helpshows--alland--verbose. - Alias parsing:
author-evidence --helpsucceeds and showsUsage: habeas author, so the alias resolves to the same command. - Parse errors: three invalid invocations cover an unknown option, a missing required argument, and a conflicting argument (
author x --all, which hits the ArgGroup and conflict rules). Each asserts exit code 2 and clap’s error text plus aUsage: habeasline on stderr.
I read src/main.rs (struct[Cli], enum[Command]) to confirm the CLI is built from clap’s Parser, Subcommand, command and arg attributes. The test exercises the commands, option kinds, alias, hidden commands and usage errors those attributes define.
Not every subcommand, such as coverage or test, is exercised individually. The requirement does not enumerate commands, and they all go through the same clap derive mechanism, so I don’t count that as a gap. The assertions would fail if parsing or help were hand-rolled rather than done by clap, so I found no adequacy gap.
Inputs
Tests
Input 2: outline tests/cli.rs fn[clap_defines_commands_options_and_usage_errors]
- File:
tests/cli.rs - Selector:
fn[clap_defines_commands_options_and_usage_errors] - Kind:
fn tests/cli.rs:43–96
// {test}`requirements.cli.clap`
#[test]
fn clap_defines_commands_options_and_usage_errors() {
let binary = env!("CARGO_BIN_EXE_habeas");
let help = Command::new(binary).arg("--help").output().unwrap();
assert!(help.status.success());
let help = String::from_utf8(help.stdout).unwrap();
assert!(help.starts_with("Usage: habeas <COMMAND>"), "{help}");
for command in ["mdbook", "setup", "status", "info", "author", "help"] {
assert!(
help.contains(&format!("\n {command} ")),
"{command}: {help}"
);
}
assert!(
!help.contains("hook"),
"hidden commands stay out of help: {help}"
);
let status = Command::new(binary)
.args(["status", "--help"])
.output()
.unwrap();
let status = String::from_utf8(status.stdout).unwrap();
assert!(
status.contains("--all") && status.contains("--verbose"),
"{status}"
);
// The alias parses to the same command.
let alias = Command::new(binary)
.args(["author-evidence", "--help"])
.output()
.unwrap();
assert!(alias.status.success());
assert!(String::from_utf8_lossy(&alias.stdout).contains("Usage: habeas author"));
for (args, expected) in [
(
["status", "--bogus"].as_slice(),
"unexpected argument '--bogus'",
),
(["info"].as_slice(), "required arguments were not provided"),
(["author", "x", "--all"].as_slice(), "cannot be used with"),
] {
let output = Command::new(binary).args(args).output().unwrap();
assert_eq!(output.status.code(), Some(2), "{args:?}");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains(expected) && stderr.contains("Usage: habeas"),
"{args:?}: {stderr}"
);
}
}
Other sources
Input 1: requirements selection requirements.cli.clap
requirements.cli.clap:md/requirements/cli.md:3–5
:::{req} clap
The `habeas` CLI MUST use `clap` to define and parse its commands and options.
:::