From 3d3c965dbaaf2a46b649c4712dcb39934d9cfb0e Mon Sep 17 00:00:00 2001 From: Adam Siwiec <73085927+adamsiwiec1@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:21:53 -0400 Subject: [PATCH] cli: add --version / -V / version flag `phishkit --version` returned a JSON "unknown command" error. Add a `--version`, `-V`, and `version` subcommand to both the `phishkit` and `phishkit_ctl` binaries that print a single line, e.g. `phishkit 0.1.1-alpha.6`. The version prefers the build-time `PHISHKIT_VERSION` env (baked by the release workflow from the tag) and falls back to `CARGO_PKG_VERSION`, so brew/cask builds report the shipped release version. release.yml now exports PHISHKIT_VERSION during the CLI build. --- .github/workflows/release.yml | 8 +++++++- apps/cli/src/phishkit.rs | 9 +++++++++ apps/cli/src/phishkit_ctl.rs | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 61816ae..1d7a368 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,7 +40,13 @@ jobs: targets: ${{ matrix.target }} - uses: Swatinem/rust-cache@v2 - name: Build CLI - run: cargo build --release -p phishkit-cli --target ${{ matrix.target }} + # Bake the release version (tag without the leading `v`) into the CLI so + # `phishkit --version` reports the shipped build, not the Cargo default. + env: + PHISHKIT_VERSION: ${{ github.ref_name }} + run: | + export PHISHKIT_VERSION="${PHISHKIT_VERSION#v}" + cargo build --release -p phishkit-cli --target ${{ matrix.target }} - name: Package shell: bash run: | diff --git a/apps/cli/src/phishkit.rs b/apps/cli/src/phishkit.rs index ec08908..589e40e 100644 --- a/apps/cli/src/phishkit.rs +++ b/apps/cli/src/phishkit.rs @@ -8,6 +8,15 @@ use serde_json::json; fn main() { let mut args = env::args().skip(1).collect::>(); + if args.iter().any(|a| a == "-V" || a == "--version") + || args.first().map(|a| a == "version").unwrap_or(false) + { + println!( + "phishkit {}", + option_env!("PHISHKIT_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")) + ); + process::exit(0); + } let wants_help = args.is_empty() || args.iter().any(|a| a == "-h" || a == "--help") || args.first().map(|a| a == "help").unwrap_or(false); diff --git a/apps/cli/src/phishkit_ctl.rs b/apps/cli/src/phishkit_ctl.rs index f87e82c..ffeb0c7 100644 --- a/apps/cli/src/phishkit_ctl.rs +++ b/apps/cli/src/phishkit_ctl.rs @@ -8,6 +8,15 @@ use serde_json::json; fn main() { let mut args = env::args().skip(1).collect::>(); + if args.iter().any(|a| a == "-V" || a == "--version") + || args.first().map(|a| a == "version").unwrap_or(false) + { + println!( + "phishkit {}", + option_env!("PHISHKIT_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")) + ); + process::exit(0); + } let wants_help = args.is_empty() || args.iter().any(|a| a == "-h" || a == "--help") || args.first().map(|a| a == "help").unwrap_or(false);