From d88d4ac30e293a05a4f746d81dc5394e358a8286 Mon Sep 17 00:00:00 2001 From: Andrea Collet Date: Tue, 24 Nov 2026 23:52:17 +0100 Subject: [PATCH] feat: add --version and -V (0.4.0) Prints migadu from Cargo.toml and exits 0 without needing credentials. Documented in the help text and the functional spec, with a test. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 7 ++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- docs/specifications/functional-spec.md | 1 + src/cli.rs | 19 ++++++++++++------- tests/cli.rs | 23 +++++++++++++++++++++++ 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0438973..c1fa06d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ User-visible and operationally material changes. Release notes with every commit ## [Unreleased] +## [0.4.0] - 2026-11-24 +### Added +- `migadu --version` (and `-V`) prints the version. + ## [0.3.4] - 2026-11-24 ### Added - Demo GIF in the README, with its recording script in `docs/demo.tape`. @@ -37,7 +41,8 @@ First published release (Node.js; versions before it were never tagged). - `migadu catchall`, `migadu spam` and `migadu bcc`, driven through the admin panel's forms. - Releases are tagged, built and published automatically when the version changes on `main`. -[Unreleased]: https://github.com/ifthenelse/migadu-cli/compare/v0.3.4...HEAD +[Unreleased]: https://github.com/ifthenelse/migadu-cli/compare/v0.4.0...HEAD +[0.4.0]: https://github.com/ifthenelse/migadu-cli/compare/v0.3.4...v0.4.0 [0.3.4]: https://github.com/ifthenelse/migadu-cli/compare/v0.3.3...v0.3.4 [0.3.3]: https://github.com/ifthenelse/migadu-cli/compare/v0.3.2...v0.3.3 [0.3.2]: https://github.com/ifthenelse/migadu-cli/compare/v0.3.1...v0.3.2 diff --git a/Cargo.lock b/Cargo.lock index abba98a..9204497 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,7 +143,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "migadu-cli" -version = "0.3.4" +version = "0.4.0" dependencies = [ "serde_json", "ureq", diff --git a/Cargo.toml b/Cargo.toml index 92bc665..3fead56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "migadu-cli" -version = "0.3.4" +version = "0.4.0" edition = "2021" rust-version = "1.85" description = "Cross-platform CLI for the Migadu email hosting API, with password-manager credential lookup." diff --git a/docs/specifications/functional-spec.md b/docs/specifications/functional-spec.md index 501b95d..5adc5a0 100644 --- a/docs/specifications/functional-spec.md +++ b/docs/specifications/functional-spec.md @@ -20,6 +20,7 @@ Errors are one line on stderr, `error: `. Output on stdout is JSON by d | `-y, --yes` | Confirms a delete or a clearing action. Without it the command refuses. | | `-o, --output json\|table` | Output format. `table` shows up to six scalar columns. | | `-h, --help` | Print usage. | +| `-V, --version` | Print `migadu ` and exit; needs no credentials. | ## Configuration | Variable | Required | Meaning | diff --git a/src/cli.rs b/src/cli.rs index c9395d6..6558341 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -30,6 +30,7 @@ Options: -y, --yes confirm delete -o, --output json|table output format (default json) -h, --help + -V, --version Plan lookup reads the admin panel with a session cookie: MIGADU_WEB_COOKIE or MIGADU_WEB_COOKIE_REF. Credentials: MIGADU_EMAIL plus MIGADU_API_KEY or MIGADU_API_KEY_REF @@ -51,6 +52,7 @@ struct Opts { yes: bool, output: String, help: bool, + version: bool, pos: Vec, } @@ -90,13 +92,11 @@ fn parse_args(args: &[String]) -> std::result::Result { "field" => o.field.push(take(&mut i, "-f, --field", inline)?), "json" => o.json = Some(take(&mut i, "--json", inline)?), "output" => o.output = take(&mut i, "-o, --output", inline)?, - "yes" | "help" if inline.is_none() => { - if name == "yes" { - o.yes = true - } else { - o.help = true - } - } + "yes" | "help" | "version" if inline.is_none() => match name { + "yes" => o.yes = true, + "help" => o.help = true, + _ => o.version = true, + }, _ => return Err(format!("Unknown option '--{name}'")), } } else { @@ -109,6 +109,7 @@ fn parse_args(args: &[String]) -> std::result::Result { match c { 'y' => o.yes = true, 'h' => o.help = true, + 'V' => o.version = true, 'd' | 'f' | 'o' => { let v = take(&mut i, &format!("-{c}"), inline)?; match c { @@ -360,6 +361,10 @@ pub fn run( return 2; } }; + if o.version { + (io.out)(&format!("migadu {}", env!("CARGO_PKG_VERSION"))); + return 0; + } let res = o.pos.first().cloned(); if o.help || res.is_none() { (io.out)(HELP.trim_end_matches('\n')); diff --git a/tests/cli.rs b/tests/cli.rs index 7a51e5e..5fd8e29 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -213,6 +213,29 @@ fn bad_options_exit_with_code_2() { assert!(help.out[0].starts_with("migadu — Migadu email hosting")); } +#[test] +fn version_flag_prints_the_crate_version_and_needs_no_credentials() { + let want = format!("migadu {}", env!("CARGO_PKG_VERSION")); + for flag in ["--version", "-V"] { + let r = run_cli(&[flag], &env(&[]), &ok_empty(), &FakeExec::new()); + assert_eq!( + (r.code, r.out.as_slice()), + (0, &[want.clone()][..]), + "{flag}" + ); + } + assert_eq!( + run_cli( + &["domains", "list", "-V"], + &env(&[]), + &ok_empty(), + &FakeExec::new() + ) + .out, + [want] + ); +} + #[test] fn table_output_lists_scalar_columns() { let h = Fake::new(|_| {