4
0

2 Ревизии 8363318364 ... 0fa89e6482

Автор SHA1 Съобщение Дата
  Steve Thielemann 0fa89e6482 Update CLI help. преди 1 седмица
  Steve Thielemann 3f060db7dd Updated go-up with version information. преди 1 седмица
променени са 5 файла, в които са добавени 111 реда и са изтрити 0 реда
  1. 59 0
      Cargo.lock
  2. 5 0
      Cargo.toml
  3. 7 0
      NOTES.md
  4. 5 0
      build.rs
  5. 35 0
      src/main.rs

+ 59 - 0
Cargo.lock

@@ -162,6 +162,15 @@ dependencies = [
  "alloc-stdlib",
 ]
 
+[[package]]
+name = "built"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64"
+dependencies = [
+ "git2",
+]
+
 [[package]]
 name = "bumpalo"
 version = "3.17.0"
@@ -211,6 +220,8 @@ version = "1.2.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a"
 dependencies = [
+ "jobserver",
+ "libc",
  "shlex",
 ]
 
@@ -452,11 +463,25 @@ version = "0.31.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
 
+[[package]]
+name = "git2"
+version = "0.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2deb07a133b1520dc1a5690e9bd08950108873d7ed5de38dcc74d3b5ebffa110"
+dependencies = [
+ "bitflags",
+ "libc",
+ "libgit2-sys",
+ "log",
+ "url",
+]
+
 [[package]]
 name = "go-up"
 version = "0.1.0"
 dependencies = [
  "anyhow",
+ "built",
  "clap",
  "reqwest",
  "testdir",
@@ -773,6 +798,16 @@ version = "1.0.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
 
+[[package]]
+name = "jobserver"
+version = "0.1.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a"
+dependencies = [
+ "getrandom 0.3.2",
+ "libc",
+]
+
 [[package]]
 name = "js-sys"
 version = "0.3.77"
@@ -789,6 +824,30 @@ version = "0.2.171"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
 
+[[package]]
+name = "libgit2-sys"
+version = "0.18.1+1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1dcb20f84ffcdd825c7a311ae347cce604a6f084a767dec4a4929829645290e"
+dependencies = [
+ "cc",
+ "libc",
+ "libz-sys",
+ "pkg-config",
+]
+
+[[package]]
+name = "libz-sys"
+version = "1.1.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b70e7a7df205e92a1a4cd9aaae7898dac0aa555503cc0a649494d0d60e7651d"
+dependencies = [
+ "cc",
+ "libc",
+ "pkg-config",
+ "vcpkg",
+]
+
 [[package]]
 name = "linux-raw-sys"
 version = "0.9.3"

+ 5 - 0
Cargo.toml

@@ -2,13 +2,18 @@
 name = "go-up"
 version = "0.1.0"
 edition = "2024"
+build = "build.rs"
 
 [dependencies]
 anyhow = "1.0.97"
+built = { version = "0.8.0", features = ["git2"] }
 clap = { version = "4.5.34", features = ["derive"] }
 reqwest = { version = "0.12.15", features = ["blocking", "brotli", "deflate", "gzip"] }
 url = "2.5.4"
 
+[build-dependencies]
+built = { version = "0.8.0", features = ["git2"] }
+
 [features]
 # add here so it shows up in vscode (enabled)
 default = ["local-httpbin"]

+ 7 - 0
NOTES.md

@@ -63,3 +63,10 @@ Extracting...
 Extract cache/go1.24.2.linux-amd64.tar.gz to /home/thor/go
 Updated 1.23.4 to 1.24.2
 ```
+
+# Version
+
+cargo add built --features git2
+
+This will allow us to display version/build/git version information.
+

+ 5 - 0
build.rs

@@ -0,0 +1,5 @@
+
+fn main() {
+    built::write_built_file().expect("Failed to acquire build-time information.");
+}
+

+ 35 - 0
src/main.rs

@@ -12,6 +12,12 @@ use std::time::Duration;
 
 mod cache;
 
+// Build-time information
+pub mod built_info {
+    // The file has been placed there by the build script.
+    include!(concat!(env!("OUT_DIR"), "/built.rs"));
+}
+
 #[derive(Parser)]
 #[command(
     about = "Go Updater",
@@ -38,6 +44,8 @@ enum Commands {
     Update {},
     /// Display information
     Info {},
+    /// Display version information
+    Version {},
 }
 
 /// Query `go env`
@@ -427,6 +435,33 @@ fn main() -> Result<()> {
             println!("go os       {}", go_os);
             println!("go os arch: {}", go_os_arch);
         }
+        Some(Commands::Version {}) => {
+            println!(
+                "This is version {}, built for {} by {}.\n",
+                built_info::PKG_VERSION,
+                built_info::TARGET,
+                built_info::RUSTC_VERSION
+            );
+
+            if let (Some(v), Some(dirty), Some(hash), Some(_short_hash)) = (
+                built_info::GIT_VERSION,
+                built_info::GIT_DIRTY,
+                built_info::GIT_COMMIT_HASH,
+                built_info::GIT_COMMIT_HASH_SHORT,
+            ) {
+                print!(
+                    "I was built from git `{}`, commit {}.\nThe working directory was \"{}\".",
+                    v,
+                    hash,
+                    if dirty { "dirty" } else { "clean" }
+                );
+            }
+
+            match built_info::GIT_HEAD_REF {
+                Some(r) => println!(" The branch was `{r}`.\n"),
+                None => println!("\n"),
+            }
+        }
         None => {
             // Display help.
             let _show_help: Cli = Cli::parse_from(["", "--help"]);