Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/cli/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn entries() -> Vec<Entry> {
}
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",
Expand Down Expand Up @@ -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}");
}
Expand Down
8 changes: 7 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! - `torchio watch [--url <url>] [--interval <seconds>] [--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 <bash|zsh|fish>`: the script that completes the commands in a shell;
//! - `torchio cpu 80`, `torchio memory 512`…: start a test on a running server.
mod action;
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/cli_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
Loading