diff --git a/yazi-config/Cargo.toml b/yazi-config/Cargo.toml index d4bd4209..3c1b49a5 100644 --- a/yazi-config/Cargo.toml +++ b/yazi-config/Cargo.toml @@ -31,3 +31,4 @@ clap = { version = "^4", features = [ "derive" ] } clap_complete = "^4" clap_complete_nushell = "^4" clap_complete_fig = "^4" +vergen = { version = "8.2.6", features = ["build", "git", "gitcl" ] } diff --git a/yazi-config/build.rs b/yazi-config/build.rs index c46a35b3..f4f1ed57 100644 --- a/yazi-config/build.rs +++ b/yazi-config/build.rs @@ -1,12 +1,15 @@ #[path = "src/boot/cli.rs"] mod cli; -use std::{env, fs, io}; +use std::{env, error::Error, fs}; use clap::CommandFactory; use clap_complete::{generate_to, Shell}; +use vergen::EmitBuilder; + +fn main() -> Result<(), Box> { + EmitBuilder::builder().all_build().all_git().emit()?; -fn main() -> io::Result<()> { if env::var_os("YAZI_GEN_COMPLETIONS").is_none() { return Ok(()); } @@ -23,5 +26,6 @@ fn main() -> io::Result<()> { generate_to(Shell::PowerShell, cmd, bin, out)?; generate_to(clap_complete_nushell::Nushell, cmd, bin, out)?; generate_to(clap_complete_fig::Fig, cmd, bin, out)?; + Ok(()) } diff --git a/yazi-config/src/boot/boot.rs b/yazi-config/src/boot/boot.rs index f207d350..ddb6376e 100644 --- a/yazi-config/src/boot/boot.rs +++ b/yazi-config/src/boot/boot.rs @@ -36,6 +36,15 @@ impl Boot { impl Default for Boot { fn default() -> Self { let args = Args::parse(); + if args.version { + println!( + "yazi {} ({} {})", + env!("CARGO_PKG_VERSION"), + &env!("VERGEN_GIT_SHA")[0..9], + env!("VERGEN_BUILD_DATE") + ); + process::exit(0); + } let (cwd, file) = Self::parse_entry(args.entry); let boot = Self { diff --git a/yazi-config/src/boot/cli.rs b/yazi-config/src/boot/cli.rs index f18cf09c..111e1345 100644 --- a/yazi-config/src/boot/cli.rs +++ b/yazi-config/src/boot/cli.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use clap::{command, Parser}; #[derive(Debug, Parser)] -#[command(name = "yazi", version)] +#[command(name = "yazi")] pub(super) struct Args { /// Set the current working entry #[arg(index = 1)] @@ -19,4 +19,8 @@ pub(super) struct Args { /// Clear the cache directory #[arg(long, action)] pub clear_cache: bool, + + /// Print version + #[arg(short = 'V', long)] + pub version: bool, }