Skip to content

Commit

Permalink
fix: add full build information
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Nov 22, 2023
1 parent fd4ad44 commit 4b66c15
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 2 deletions.
177 changes: 177 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.9"
authors = ["thinkgo <[email protected]>"]
edition = "2021"
rust-version = "1.70.0"
build = "build.rs"
description = "govm is is an elegant Go version manager"
keywords = [
"goup",
Expand All @@ -22,6 +23,7 @@ repository = "https://github.com/thinkgos/govm"

[build-dependencies]
version_check = "0.9"
shadow-rs = "0.24"

[dependencies]
clap = {version = "4.4", features = ["derive", "env"]}
Expand All @@ -38,6 +40,7 @@ flate2 = "1.0"
tar = "0.4"
zip = "0.6"
self_update = {version = "0.39", default-features = false, features = ["rustls", "compression-flate2", "compression-zip-deflate"]}
shadow-rs = "0.24"
# git2 = "0.18"

[profile.dev.package."*"]
Expand Down
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const MIN_VERSION: &str = "1.70";
fn main() {

fn main() -> Result<(), shadow_rs::ShadowError> {
match version_check::is_min_version(MIN_VERSION) {
Some(true) => {}
// rustc version too small or can't figure it out
Expand All @@ -8,4 +9,5 @@ fn main() {
std::process::exit(1);
}
}
shadow_rs::new()
}
35 changes: 34 additions & 1 deletion src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ mod search;
mod set;
mod upgrade;

use clap::builder::{IntoResettable, Resettable, Str};
use clap::{ArgAction, Args, CommandFactory};
use clap::{Parser, Subcommand};
use shadow_rs::shadow;
use std::env::consts::{ARCH, OS};

use self::completion::Completion;
use self::install::Install;
Expand All @@ -17,6 +20,27 @@ use self::search::Search;
use self::set::Set;
use self::upgrade::Upgrade;

shadow!(build);
pub const VERSION: &str = shadow_rs::formatcp!(
r#"{}
auth: {}
git_commit: {}
git_full_commit: {}
build_time: {}
build_env: {},{}
build_os: {}
build_arch: {}"#,
build::PKG_VERSION,
build::COMMIT_AUTHOR,
build::SHORT_COMMIT,
build::COMMIT_HASH,
build::BUILD_TIME_2822,
build::RUST_VERSION,
build::RUST_CHANNEL,
OS,
ARCH,
);

// run command.
pub trait Run {
fn run(&self) -> Result<(), anyhow::Error>;
Expand All @@ -30,8 +54,9 @@ pub struct Global {
}

#[derive(Parser, Debug, PartialEq)]
#[command(author, version, about, long_about = None)]
#[command(author, about, long_about = None)]
#[command(propagate_version = true)]
#[command(version = VERSION)]
pub struct Cli {
#[command(flatten)]
pub global: Global,
Expand Down Expand Up @@ -76,3 +101,11 @@ impl Run for Cli {
}
}
}

struct V {}

impl IntoResettable<Str> for V {
fn into_resettable(self) -> Resettable<Str> {
Resettable::Value(build::CLAP_LONG_VERSION.into())
}
}

0 comments on commit 4b66c15

Please sign in to comment.