feat: include commit hash in yazi --version

This commit is contained in:
Hanaasagi 2023-11-23 00:39:16 +09:00
parent 5439c80a03
commit 43fb9fe3f7
4 changed files with 21 additions and 3 deletions

View file

@ -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" ] }

View file

@ -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<dyn Error>> {
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(())
}

View file

@ -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 {

View file

@ -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,
}