mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: ya add git hash to -V
This commit is contained in:
parent
aee65bc4d1
commit
957bfddd3b
5 changed files with 30 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2737,6 +2737,7 @@ dependencies = [
|
||||||
"clap_complete_nushell",
|
"clap_complete_nushell",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"vergen",
|
||||||
"yazi-dds",
|
"yazi-dds",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ clap_complete = "4.5.2"
|
||||||
clap_complete_fig = "4.5.0"
|
clap_complete_fig = "4.5.0"
|
||||||
clap_complete_nushell = "4.5.1"
|
clap_complete_nushell = "4.5.1"
|
||||||
serde_json = "1.0.116"
|
serde_json = "1.0.116"
|
||||||
|
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "ya"
|
name = "ya"
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@ use std::{env, error::Error};
|
||||||
|
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
use clap_complete::{generate_to, Shell};
|
use clap_complete::{generate_to, Shell};
|
||||||
|
use vergen::EmitBuilder;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
EmitBuilder::builder().build_date().git_sha(true).emit()?;
|
||||||
|
|
||||||
if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
|
if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,14 @@ use anyhow::{bail, Result};
|
||||||
use clap::{command, Parser, Subcommand};
|
use clap::{command, Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "ya", version, about, long_about = None)]
|
#[command(name = "ya")]
|
||||||
#[command(propagate_version = true)]
|
|
||||||
pub(super) struct Args {
|
pub(super) struct Args {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub(super) command: Command,
|
pub(super) command: Option<Command>,
|
||||||
|
|
||||||
|
/// Print version
|
||||||
|
#[arg(short = 'V', long)]
|
||||||
|
pub version: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
mod args;
|
mod args;
|
||||||
|
|
||||||
|
use std::process;
|
||||||
|
|
||||||
use args::*;
|
use args::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
|
@ -7,22 +9,36 @@ use clap::Parser;
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
match &args.command {
|
if args.version {
|
||||||
|
println!("Ya {}", action_version());
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
match &args.command.expect("No command provided") {
|
||||||
Command::Pub(cmd) => {
|
Command::Pub(cmd) => {
|
||||||
yazi_dds::init();
|
yazi_dds::init();
|
||||||
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, None, &cmd.body()?).await {
|
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, None, &cmd.body()?).await {
|
||||||
eprintln!("Cannot send message: {e}");
|
eprintln!("Cannot send message: {e}");
|
||||||
std::process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::PubStatic(cmd) => {
|
Command::PubStatic(cmd) => {
|
||||||
yazi_dds::init();
|
yazi_dds::init();
|
||||||
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, 0, Some(cmd.severity), &cmd.body()?).await {
|
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, 0, Some(cmd.severity), &cmd.body()?).await {
|
||||||
eprintln!("Cannot send message: {e}");
|
eprintln!("Cannot send message: {e}");
|
||||||
std::process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn action_version() -> String {
|
||||||
|
format!(
|
||||||
|
"{} ({} {})",
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
env!("VERGEN_GIT_SHA"),
|
||||||
|
env!("VERGEN_BUILD_DATE")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue