feat: add git commit hash to ya --version (#1006)

Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
like 2024-05-05 01:16:31 +08:00 committed by GitHub
parent 668279814c
commit fdecf629a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 4 deletions

1
Cargo.lock generated
View File

@ -2737,6 +2737,7 @@ dependencies = [
"clap_complete_nushell",
"serde_json",
"tokio",
"vergen",
"yazi-dds",
]

View File

@ -24,6 +24,7 @@ clap_complete = "4.5.2"
clap_complete_fig = "4.5.0"
clap_complete_nushell = "4.5.1"
serde_json = "1.0.116"
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
[[bin]]
name = "ya"

View File

@ -5,8 +5,11 @@ use std::{env, error::Error};
use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
use vergen::EmitBuilder;
fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder().build_date().git_sha(true).emit()?;
if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
return Ok(());
}

View File

@ -4,11 +4,14 @@ use anyhow::{bail, Result};
use clap::{command, Parser, Subcommand};
#[derive(Parser)]
#[command(name = "ya", version, about, long_about = None)]
#[command(propagate_version = true)]
#[command(name = "Ya", about, long_about = None)]
pub(super) struct Args {
#[command(subcommand)]
pub(super) command: Command,
/// Print version
#[arg(short = 'V', long)]
pub(super) version: bool,
}
#[derive(Subcommand)]

View File

@ -5,9 +5,17 @@ use clap::Parser;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
if std::env::args_os().any(|s| s == "-V" || s == "--version") {
println!(
"Ya {} ({} {})",
env!("CARGO_PKG_VERSION"),
env!("VERGEN_GIT_SHA"),
env!("VERGEN_BUILD_DATE")
);
return Ok(());
}
match &args.command {
match Args::parse().command {
Command::Pub(cmd) => {
yazi_dds::init();
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, None, &cmd.body()?).await {