feat(cli): --version/-V + in-app version command + release guard (ADR-0054)
Cargo.toml version is the single source of truth, surfaced by a --version/-V CLI flag and an in-app `version` command (both via cli::version_text -> cli.version_line). release.yaml gains a guard that fails the release unless the v* tag equals v<CARGO_PKG_VERSION>, keeping --version, the release name, and the asset in lockstep. New app command wired across grammar/REGISTRY/dispatch/usage/help/hint-corpus/keys; 6 test-first tests. Also fixes a stale "macOS deferred" comment in release.yaml. ADR-0054 + README index + plan-doc step 1.
This commit is contained in:
+49
@@ -30,6 +30,10 @@ pub struct Args {
|
||||
/// `--help` / `-h`: print usage to stdout and exit. The
|
||||
/// runtime checks this flag before doing any other work.
|
||||
pub help: bool,
|
||||
/// `--version` / `-V`: print the version (`CARGO_PKG_VERSION`,
|
||||
/// the single source of truth — ADR-0054) and exit. Checked
|
||||
/// alongside `--help` before any other work.
|
||||
pub version: bool,
|
||||
/// `--no-undo`: disable the auto-snapshot / undo machinery for
|
||||
/// this run (ADR-0006 Amendment 1). When set, no snapshots are
|
||||
/// taken — zero per-command overhead — and `undo` / `redo`
|
||||
@@ -62,6 +66,17 @@ pub fn help_text() -> String {
|
||||
crate::t!("help.cli_banner")
|
||||
}
|
||||
|
||||
/// Version line printed by `--version` / `-V` and the in-app `version`
|
||||
/// command (ADR-0054).
|
||||
///
|
||||
/// `CARGO_PKG_VERSION` is the single source of truth — it equals the `v*`
|
||||
/// release tag (the release CI guards that), so what the binary reports
|
||||
/// always matches the downloaded artifact.
|
||||
#[must_use]
|
||||
pub fn version_text() -> String {
|
||||
crate::t!("cli.version_line", version = env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ArgsError {
|
||||
MissingValue(&'static str),
|
||||
@@ -129,6 +144,7 @@ impl Args {
|
||||
let mut project_path: Option<PathBuf> = None;
|
||||
let mut resume = false;
|
||||
let mut help = false;
|
||||
let mut version = false;
|
||||
let mut no_undo = false;
|
||||
let mut mode: Option<Mode> = None;
|
||||
// Demonstration mode (ADR-0047): the env var is the default,
|
||||
@@ -143,6 +159,9 @@ impl Args {
|
||||
"--help" | "-h" => {
|
||||
help = true;
|
||||
}
|
||||
"--version" | "-V" => {
|
||||
version = true;
|
||||
}
|
||||
"--resume" => {
|
||||
resume = true;
|
||||
}
|
||||
@@ -208,6 +227,7 @@ impl Args {
|
||||
project_path,
|
||||
resume,
|
||||
help,
|
||||
version,
|
||||
no_undo,
|
||||
mode,
|
||||
demo,
|
||||
@@ -475,4 +495,33 @@ mod tests {
|
||||
let err = Args::parse(["--bogus", "/some/path"]).unwrap_err();
|
||||
assert!(matches!(&err, ArgsError::Unknown(s) if s == "--bogus"), "got: {err:?}");
|
||||
}
|
||||
|
||||
// ---- ADR-0054: --version / -V ----
|
||||
|
||||
#[test]
|
||||
fn version_long_flag_parses() {
|
||||
assert!(Args::parse(["--version"]).unwrap().version);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_short_flag_parses() {
|
||||
assert!(Args::parse(["-V"]).unwrap().version);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_defaults_off() {
|
||||
assert!(!Args::parse(std::iter::empty::<&str>()).unwrap().version);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_text_carries_the_cargo_version() {
|
||||
// The binary's self-reported version IS Cargo.toml's (the
|
||||
// single source of truth, ADR-0054) — and the release CI guards
|
||||
// that the `v*` tag equals it.
|
||||
let text = version_text();
|
||||
assert!(
|
||||
text.contains(env!("CARGO_PKG_VERSION")),
|
||||
"version line should embed CARGO_PKG_VERSION; got {text:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user