feat: add --verbose flag to version command

This commit is contained in:
Cyborus 2024-12-10 16:38:07 -05:00
parent 08e9fa2dce
commit 6a592b38d7
6 changed files with 32 additions and 1 deletions

View file

@ -3,6 +3,8 @@ when:
steps:
compile-linux:
image: rust:latest
environment:
BUILD_TYPE: "release ci"
commands:
- rustup target add x86_64-unknown-linux-gnu
- cargo build --target=x86_64-unknown-linux-gnu --release --features update-check
@ -10,6 +12,8 @@ steps:
secrets: [ client_info_codeberg ]
compile-windows:
image: rust:latest
environment:
BUILD_TYPE: "release ci"
commands:
- rustup target add x86_64-pc-windows-gnu
- apt update

1
Cargo.lock generated
View file

@ -603,6 +603,7 @@ version = "0.1.1"
dependencies = [
"auth-git2",
"base64ct",
"cfg-if",
"clap",
"comrak",
"crossterm",

View file

@ -20,6 +20,7 @@ update-check = ["dep:semver"]
[dependencies]
auth-git2 = "0.5.4"
base64ct = { version = "1.6.0", features = ["std"] }
cfg-if = "1.0.0"
clap = { version = "4.5.11", features = ["derive"] }
comrak = "0.26.0"
crossterm = "0.27.0"
@ -42,3 +43,6 @@ tokio = { version = "1.39.1", features = ["full"] }
url = "2.5.2"
uuid = { version = "1.10.0", features = ["v4"] }
[build-dependencies]
git2 = "0.19.0"

6
build.rs Normal file
View file

@ -0,0 +1,6 @@
fn main() {
println!(
"cargo:rustc-env=BUILD_TARGET={}",
std::env::var("TARGET").unwrap()
);
}

View file

@ -24,6 +24,10 @@
homepage = "https://codeberg.org/Cyborus/forgejo-cli/";
license = with licenses; [ asl20 /* or */ mit ];
};
env = {
BUILD_TYPE = "flake";
};
};
packages.default = packages.forgejo-cli;

View file

@ -8,11 +8,23 @@ pub struct VersionCommand {
#[clap(long)]
#[cfg(feature = "update-check")]
check: bool,
#[clap(short, long)]
verbose: bool,
}
const BUILD_TYPE: &str = match option_env!("BUILD_TYPE") {
Some(s) => s,
None => "from source",
};
impl VersionCommand {
pub async fn run(self) -> eyre::Result<()> {
println!("{}", env!("CARGO_PKG_VERSION"));
println!("{} v{}", env!("CARGO_BIN_NAME"), env!("CARGO_PKG_VERSION"));
if self.verbose {
println!("user agent: {}", crate::keys::USER_AGENT);
println!("build type: {BUILD_TYPE}");
println!(" target: {}", env!("BUILD_TARGET"));
}
#[cfg(feature = "update-check")]
self.update_msg().await?;
Ok(())