From 5991905ae9fb519a3a43c599c5515ba39c04e5fb Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 4 Nov 2025 14:29:34 +0800 Subject: Add compile-time version and build information - Add build script to generate compile_info.rs with build metadata - Include version, build date, target platform, and toolchain info - Add version command to both jv and jvv binaries - Update help documentation with version information - Ignore generated compile_info.rs in git --- src/bin/jv.rs | 39 +++++++++++++++++++++++++++++++++++++-- src/bin/jvv.rs | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 4 deletions(-) (limited to 'src/bin') diff --git a/src/bin/jv.rs b/src/bin/jv.rs index b7eb105..8ccd843 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -30,8 +30,11 @@ use just_enough_vcs::{ utils::tcp_connection::error::TcpTargetError, vcs::{actions::local_actions::proc_set_upstream_vault_action, registry::client_registry}, }; -use just_enough_vcs_cli::utils::{ - input::confirm_hint_or, lang_selector::current_locales, md_colored::md, socket_addr_helper, +use just_enough_vcs_cli::{ + data::compile_info::CompileInfo, + utils::{ + input::confirm_hint_or, lang_selector::current_locales, md_colored::md, socket_addr_helper, + }, }; use rust_i18n::{set_locale, t}; use tokio::{fs, net::TcpSocket}; @@ -54,6 +57,11 @@ struct JustEnoughVcsWorkspace { #[derive(Subcommand, Debug)] enum JustEnoughVcsWorkspaceCommand { + /// Version information + #[command(alias = "--version", alias = "-v")] + Version(VersionArgs), + + /// Display help information #[command(alias = "--help", alias = "-h")] Help, @@ -130,6 +138,12 @@ enum JustEnoughVcsWorkspaceCommand { Sheets, } +#[derive(Parser, Debug)] +struct VersionArgs { + #[arg(short = 'C', long = "compile-info")] + compile_info: bool, +} + #[derive(Subcommand, Debug)] enum AccountManage { /// Show help information @@ -407,6 +421,27 @@ async fn main() { }; match parser.command { + JustEnoughVcsWorkspaceCommand::Version(version_args) => { + let compile_info = CompileInfo::default(); + println!( + "{}", + md(t!("jv.version.header", version = compile_info.cli_version)) + ); + + if version_args.compile_info { + println!( + "\n{}", + md(t!( + "jv.version.compile_info", + build_time = compile_info.date, + build_target = compile_info.target, + build_platform = compile_info.platform, + build_toolchain = compile_info.toolchain + )) + ); + } + } + JustEnoughVcsWorkspaceCommand::Help => { println!("{}", md(t!("jv.help"))); } diff --git a/src/bin/jvv.rs b/src/bin/jvv.rs index 8480029..8dc9c88 100644 --- a/src/bin/jvv.rs +++ b/src/bin/jvv.rs @@ -16,8 +16,9 @@ use just_enough_vcs::{ }, }, }; -use just_enough_vcs_cli::utils::{ - build_env_logger::build_env_logger, lang_selector::current_locales, md_colored::md, +use just_enough_vcs_cli::{ + data::compile_info::CompileInfo, + utils::{build_env_logger::build_env_logger, lang_selector::current_locales, md_colored::md}, }; use log::{error, info}; use rust_i18n::{set_locale, t}; @@ -40,6 +41,10 @@ struct JustEnoughVcsVault { #[derive(Subcommand, Debug)] enum JustEnoughVcsVaultCommand { + /// Version information + #[command(alias = "--version", alias = "-v")] + Version(VersionArgs), + /// Get vault info in the current directory #[command(alias = "-H")] Here(HereArgs), @@ -65,6 +70,12 @@ enum JustEnoughVcsVaultCommand { ServiceListen(ListenArgs), } +#[derive(Parser, Debug)] +struct VersionArgs { + #[arg(short = 'C', long = "compile-info")] + compile_info: bool, +} + #[derive(Subcommand, Debug)] enum MemberManage { /// Register a member to the vault @@ -178,6 +189,27 @@ async fn main() { }; match parser.command { + JustEnoughVcsVaultCommand::Version(version_args) => { + let compile_info = CompileInfo::default(); + println!( + "{}", + md(t!("jvv.version.header", version = compile_info.cli_version)) + ); + + if version_args.compile_info { + println!( + "\n{}", + md(t!( + "jvv.version.compile_info", + build_time = compile_info.date, + build_target = compile_info.target, + build_platform = compile_info.platform, + build_toolchain = compile_info.toolchain + )) + ); + } + } + JustEnoughVcsVaultCommand::Here(here_args) => { if here_args.help { println!("{}", md(t!("jvv.here"))); -- cgit