From 2f45c6f95bca6a7a2983a0afab8f167baae95e3d Mon Sep 17 00:00:00 2001 From: altrdev Date: Mon, 19 Oct 2026 19:48:22 +0200 Subject: [PATCH] feat: torchio version, --version and -V Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 5 +++++ src/cli/completions.rs | 3 ++- src/cli/mod.rs | 8 +++++++- tests/cli_body.rs | 9 +++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa1ba6b..70cd3ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project are documented here. The GitHub release of each version uses the matching section. +## Unreleased + +### Added +- `torchio version` (also `--version` and `-V`) prints the version of the binary, which was only in `/info` until now. It is in the shell completions. + ## 4.5.0 - 2026-10-19 ### Added diff --git a/src/cli/completions.rs b/src/cli/completions.rs index 1ff0c90..9381191 100644 --- a/src/cli/completions.rs +++ b/src/cli/completions.rs @@ -59,6 +59,7 @@ fn entries() -> Vec { } entries.push(Entry { name, about, options, words }); } + entries.push(Entry { name: "version", about: "Print the version", options: vec![], words: vec![] }); entries.push(Entry { name: "healthcheck", about: "Exit with 0 when the server answers", options: vec![], words: vec![] }); entries.push(Entry { name: "completions", @@ -169,7 +170,7 @@ mod tests { #[test] fn every_command_is_in_every_script() { - for name in action::names().into_iter().chain(["serve", "watch", "healthcheck", "completions", "help"]) { + for name in action::names().into_iter().chain(["serve", "watch", "healthcheck", "completions", "version", "help"]) { for (shell, script) in [("bash", bash()), ("zsh", zsh()), ("fish", fish())] { assert!(script.contains(name), "{name} is missing from {shell}"); } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ca9f93b..9aabed2 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -4,6 +4,7 @@ //! - `torchio watch [--url ] [--interval ] [--once] [--read-only]`: a terminal view of //! `/info`, with keys that start the tests unless it is read only; //! - `torchio healthcheck`: exits with 0 when the server answers; +//! - `torchio version`: prints the version; //! - `torchio completions `: the script that completes the commands in a shell; //! - `torchio cpu 80`, `torchio memory 512`…: start a test on a running server. mod action; @@ -48,7 +49,8 @@ The two that send or read a body (--url and --token work on both): Other commands: torchio serve start the server (the same as torchio with no command) torchio completions print the completion script of a shell: bash, zsh or fish - torchio healthcheck exit with status 0 when the server answers on $PORT (or 3000)"; + torchio healthcheck exit with status 0 when the server answers on $PORT (or 3000) + torchio version print the version (also --version and -V)"; /// Runs the command in `args` (what follows the name of the program) and says how it ended pub fn run(args: &[String]) -> ExitCode { @@ -61,6 +63,10 @@ pub fn run(args: &[String]) -> ExitCode { Some("payload") => body::payload(&args[1..]), Some("healthcheck") => healthcheck::run(), Some("completions") => completions::run(&args[1..]), + Some("version" | "--version" | "-V") => { + println!("torchio {}", env!("CARGO_PKG_VERSION")); + ExitCode::SUCCESS + } Some("help" | "--help" | "-h") => { println!("{USAGE}"); ExitCode::SUCCESS diff --git a/tests/cli_body.rs b/tests/cli_body.rs index 003dbf2..3006432 100644 --- a/tests/cli_body.rs +++ b/tests/cli_body.rs @@ -135,3 +135,12 @@ fn payload_needs_its_words() { assert!(text(&output.stderr).starts_with("Usage: torchio payload"), "{args:?}: {}", text(&output.stderr)); } } + +#[test] +fn version_prints_the_version_of_the_binary_in_the_three_spellings() { + for flag in ["version", "--version", "-V"] { + let out = run(&[flag], &[]); + assert!(out.status.success(), "{flag}"); + assert_eq!(text(&out.stdout).trim(), concat!("torchio ", env!("CARGO_PKG_VERSION")), "{flag}"); + } +}