Skip to content

Commit de8a8e9

Browse files
kixelatedclaude
andauthored
Add --version flag to all CLI tools (#1203)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 815cfe6 commit de8a8e9

9 files changed

Lines changed: 129 additions & 1 deletion

File tree

rs/moq-cli/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
println!("cargo:rerun-if-changed=../../.git/HEAD");
5+
println!("cargo:rerun-if-changed=../../.git/refs/heads");
6+
println!("cargo:rerun-if-changed=../../.git/refs/tags");
7+
println!("cargo:rerun-if-changed=../../.git/packed-refs");
8+
9+
let prefix = "moq-cli-v";
10+
let version = git_version(prefix).unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
11+
println!("cargo:rustc-env=VERSION={version}");
12+
}
13+
14+
fn git_version(prefix: &str) -> Option<String> {
15+
let output = Command::new("git")
16+
.args(["describe", "--tags", "--match", &format!("{prefix}*")])
17+
.output()
18+
.ok()?;
19+
if !output.status.success() {
20+
return None;
21+
}
22+
let desc = String::from_utf8(output.stdout).ok()?.trim().to_string();
23+
let version = desc.strip_prefix(prefix)?;
24+
// "0.7.13-3-gabcdef" → "0.7.13-abcdef" (drop count, strip 'g')
25+
if let Some((base, hash)) = version.rsplit_once("-g") {
26+
let base = base.rsplit_once('-').map(|(b, _)| b).unwrap_or(base);
27+
Some(format!("{base}-{hash}"))
28+
} else {
29+
Some(version.to_string())
30+
}
31+
}

rs/moq-cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::path::PathBuf;
1313
use url::Url;
1414

1515
#[derive(Parser, Clone)]
16+
#[command(version = env!("VERSION"))]
1617
pub struct Cli {
1718
#[command(flatten)]
1819
log: moq_native::Log,

rs/moq-clock/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
println!("cargo:rerun-if-changed=../../.git/HEAD");
5+
println!("cargo:rerun-if-changed=../../.git/refs/heads");
6+
println!("cargo:rerun-if-changed=../../.git/refs/tags");
7+
println!("cargo:rerun-if-changed=../../.git/packed-refs");
8+
9+
let prefix = "moq-clock-v";
10+
let version = git_version(prefix).unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
11+
println!("cargo:rustc-env=VERSION={version}");
12+
}
13+
14+
fn git_version(prefix: &str) -> Option<String> {
15+
let output = Command::new("git")
16+
.args(["describe", "--tags", "--match", &format!("{prefix}*")])
17+
.output()
18+
.ok()?;
19+
if !output.status.success() {
20+
return None;
21+
}
22+
let desc = String::from_utf8(output.stdout).ok()?.trim().to_string();
23+
let version = desc.strip_prefix(prefix)?;
24+
// "0.10.11-3-gabcdef" → "0.10.11-abcdef" (drop count, strip 'g')
25+
if let Some((base, hash)) = version.rsplit_once("-g") {
26+
let base = base.rsplit_once('-').map(|(b, _)| b).unwrap_or(base);
27+
Some(format!("{base}-{hash}"))
28+
} else {
29+
Some(version.to_string())
30+
}
31+
}

rs/moq-clock/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod clock;
1212
use moq_lite::*;
1313

1414
#[derive(Parser, Clone)]
15+
#[command(version = env!("VERSION"))]
1516
pub struct Config {
1617
/// Connect to the given URL starting with https://
1718
#[arg(long)]

rs/moq-relay/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Luke Curley"]
55
repository = "https://github.com/moq-dev/moq"
66
license = "MIT OR Apache-2.0"
77

8-
version = "0.10.13"
8+
version = "0.10.14"
99
edition = "2024"
1010
rust-version.workspace = true
1111

rs/moq-relay/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
println!("cargo:rerun-if-changed=../../.git/HEAD");
5+
println!("cargo:rerun-if-changed=../../.git/refs/heads");
6+
println!("cargo:rerun-if-changed=../../.git/refs/tags");
7+
println!("cargo:rerun-if-changed=../../.git/packed-refs");
8+
9+
let prefix = "moq-relay-v";
10+
let version = git_version(prefix).unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
11+
println!("cargo:rustc-env=VERSION={version}");
12+
}
13+
14+
fn git_version(prefix: &str) -> Option<String> {
15+
let output = Command::new("git")
16+
.args(["describe", "--tags", "--match", &format!("{prefix}*")])
17+
.output()
18+
.ok()?;
19+
if !output.status.success() {
20+
return None;
21+
}
22+
let desc = String::from_utf8(output.stdout).ok()?.trim().to_string();
23+
let version = desc.strip_prefix(prefix)?;
24+
// "0.10.13-3-gabcdef" → "0.10.13-abcdef" (drop count, strip 'g')
25+
if let Some((base, hash)) = version.rsplit_once("-g") {
26+
let base = base.rsplit_once('-').map(|(b, _)| b).unwrap_or(base);
27+
Some(format!("{base}-{hash}"))
28+
} else {
29+
Some(version.to_string())
30+
}
31+
}

rs/moq-relay/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{AuthConfig, ClusterConfig, WebConfig};
77
/// variables, or a TOML file.
88
#[derive(Parser, Clone, Debug, Deserialize, Serialize, Default)]
99
#[serde(deny_unknown_fields, default)]
10+
#[command(version = env!("VERSION"))]
1011
#[non_exhaustive]
1112
pub struct Config {
1213
/// The QUIC/TLS configuration for the server.

rs/moq-token-cli/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
println!("cargo:rerun-if-changed=../../.git/HEAD");
5+
println!("cargo:rerun-if-changed=../../.git/refs/heads");
6+
println!("cargo:rerun-if-changed=../../.git/refs/tags");
7+
println!("cargo:rerun-if-changed=../../.git/packed-refs");
8+
9+
let prefix = "moq-token-cli-v";
10+
let version = git_version(prefix).unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
11+
println!("cargo:rustc-env=VERSION={version}");
12+
}
13+
14+
fn git_version(prefix: &str) -> Option<String> {
15+
let output = Command::new("git")
16+
.args(["describe", "--tags", "--match", &format!("{prefix}*")])
17+
.output()
18+
.ok()?;
19+
if !output.status.success() {
20+
return None;
21+
}
22+
let desc = String::from_utf8(output.stdout).ok()?.trim().to_string();
23+
let version = desc.strip_prefix(prefix)?;
24+
// "0.5.17-3-gabcdef" → "0.5.17-abcdef" (drop count, strip 'g')
25+
if let Some((base, hash)) = version.rsplit_once("-g") {
26+
let base = base.rsplit_once('-').map(|(b, _)| b).unwrap_or(base);
27+
Some(format!("{base}-{hash}"))
28+
} else {
29+
Some(version.to_string())
30+
}
31+
}

rs/moq-token-cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{io, path::PathBuf};
66
#[derive(Debug, Parser)]
77
#[command(name = "moq-token")]
88
#[command(about = "Generate, sign, and verify tokens for moq-relay", long_about = None)]
9+
#[command(version = env!("VERSION"))]
910
struct Cli {
1011
/// The command to execute.
1112
#[command(subcommand)]

0 commit comments

Comments
 (0)