Skip to main content

xianyun_cli/commands/
version.rs

1//! `caproni version`: print build/version information.
2//!
3//! Port of Go's `cmd/version` package. This command doesn't need config.
4
5use clap::Args;
6
7use crate::buildinfo;
8
9pub const COMMAND_NAME: &str = "version";
10
11#[derive(Args, Debug)]
12pub struct VersionArgs {}
13
14/// Port of `version.CreateCommand`'s action.
15pub fn run(_args: &VersionArgs) -> anyhow::Result<()> {
16    print_version();
17    Ok(())
18}
19
20/// The printing half of `run`, pulled out so a test can capture it without
21/// going through `anyhow::Result<()>`'s indirection.
22fn print_version() {
23    println!("caproni version {}", buildinfo::version());
24    println!("  commit: {}", buildinfo::commit());
25    println!("  built:  {}", buildinfo::date());
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    /// There's no `cmd/version_test.go` in Go to port (the package has no
33    /// test file at all), so this is new coverage for the Rust port: `run`
34    /// succeeds and doesn't need a config file, matching the Go doc
35    /// comment ("This command doesn't have access to the config.").
36    #[test]
37    fn run_succeeds_without_config() {
38        assert!(run(&VersionArgs {}).is_ok());
39    }
40}