summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-14 21:39:30 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-14 21:39:30 +0800
commit54b5567d6f1b1adaa6ada6a26faba0c5c492b7f3 (patch)
tree407940ef4697e4b5eb2bf7384f26b6ec5e570a80
parent17e7b28f162b3ed75683948144237ee17f81f7a5 (diff)
Add version command with banner and compile info display
-rw-r--r--Cargo.lock1
-rw-r--r--resources/helpdoc/commands.en.md7
-rw-r--r--resources/helpdoc/commands.zh-CN.md7
-rw-r--r--resources/helpdoc/commands/version.en.md16
-rw-r--r--resources/helpdoc/commands/version.zh-CN.md15
-rw-r--r--resources/locales/jvn/cmds/version/en.yml20
-rw-r--r--resources/locales/jvn/cmds/version/zh-CN.yml20
-rw-r--r--resources/locales/jvn/en.yml20
-rw-r--r--resources/locales/jvn/zh-CN.yml1
-rw-r--r--src/bin/jvn.rs5
-rw-r--r--src/cmds/arg/version.rs8
-rw-r--r--src/cmds/cmd/version.rs55
-rw-r--r--src/cmds/collect/compile_info.rs7
-rw-r--r--src/cmds/converter/version_in_out.rs20
-rw-r--r--src/cmds/in/version.rs4
-rw-r--r--src/cmds/out/version.rs10
-rw-r--r--src/cmds/renderer/version.rs92
-rw-r--r--templates/compile_info.rs.template1
18 files changed, 309 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 47482bd..9cb9bb6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1194,6 +1194,7 @@ dependencies = [
"framework",
"hex_display",
"jvlib",
+ "serde",
"sha1_hash",
"sheet_system",
"tcp_connection",
diff --git a/resources/helpdoc/commands.en.md b/resources/helpdoc/commands.en.md
index 3a7cf06..6735831 100644
--- a/resources/helpdoc/commands.en.md
+++ b/resources/helpdoc/commands.en.md
@@ -21,6 +21,13 @@ Show command help.
> Or use `jvn helpdoc <DOCUMENT>`
> for full docs.
+### Version
+**Flag**: `--version` or `-v`
+Redirects the current command to the `version` command
+to display version information.
+> For usage of the version command,
+> see `commands/version`
+
### Renderer Override
**Flag**: `--renderer <RENDERER>`
Override output format.
diff --git a/resources/helpdoc/commands.zh-CN.md b/resources/helpdoc/commands.zh-CN.md
index fc734cf..909e4fb 100644
--- a/resources/helpdoc/commands.zh-CN.md
+++ b/resources/helpdoc/commands.zh-CN.md
@@ -21,6 +21,13 @@ jvn <子命令> <参数: ?> <标识符: ?>
> 当然,您也可以用 `jvn helpdoc <文档>`
> 来打开帮助文档页面
+### 显示版本
+**符号**:`--version` 或 `-v`
+将当前命令重新定向到 `version` 命令
+以显示版本信息
+> 关于 version 命令的用法,
+> 请查询 `commands/version`
+
### 渲染器覆盖
**符号**:`--renderer <渲染器>`
指定覆盖渲染器,将结果以指定格式输出
diff --git a/resources/helpdoc/commands/version.en.md b/resources/helpdoc/commands/version.en.md
new file mode 100644
index 0000000..2c3f5ae
--- /dev/null
+++ b/resources/helpdoc/commands/version.en.md
@@ -0,0 +1,16 @@
+> Display version information for the `jvn` tool
+
+## Usage
+jvn version # Show basic version
+jvn version --no-banner # Hide banner
+
+jvn version --with-compile-info
+jvn version -c # Display compile info
+
+## Aliases
+You can use the `-v` or `--version` flags to
+ redirect the command to version.
+
+### Example
+jvn -v -c
+jvn --version --no-banner
diff --git a/resources/helpdoc/commands/version.zh-CN.md b/resources/helpdoc/commands/version.zh-CN.md
new file mode 100644
index 0000000..3c3935d
--- /dev/null
+++ b/resources/helpdoc/commands/version.zh-CN.md
@@ -0,0 +1,15 @@
+> 显示 `jvn` 工具的版本信息
+
+## 使用
+jvn version # 显示基础版本号
+jvn version --no-banner # 不显示横幅,仅输出版本信息
+
+jvn version --with-compile-info
+jvn version -c # 显示版本号及编译信息
+
+## 别名
+您可以使用 `-v` 或 `--version` 符号将命令重定向到 version
+
+### 例如
+jvn -v -c
+jvn --version --no-banner
diff --git a/resources/locales/jvn/cmds/version/en.yml b/resources/locales/jvn/cmds/version/en.yml
new file mode 100644
index 0000000..2f48936
--- /dev/null
+++ b/resources/locales/jvn/cmds/version/en.yml
@@ -0,0 +1,20 @@
+version:
+ banner_title_line: JustEnoughVCS
+ banner_cmd_version: |
+ CORE: %{cli_version} (%{build_time})
+ banner_core_version: |
+ CLI: %{core_version}
+ no_banner_output: |
+ %{version}
+ no_banner_output_with_compile_info: |
+ VERSION: %{version}
+
+ compile_info:
+ info: |
+ COMPILE_INFO:
+ __ Date: [[cyan]]%{build_time}[[/]]
+ __ Target: [[cyan]]%{target}[[/]]
+ __ Platform:[[cyan]]%{platform} - %{toolchain}[[/]]
+
+ __ CORE:[[cyan]]%{core_branch}[[/]] (Commit: %{core_commit})
+ __ CLI:[[cyan]]%{cli_branch}[[/]] (Commit: %{cli_commit})
diff --git a/resources/locales/jvn/cmds/version/zh-CN.yml b/resources/locales/jvn/cmds/version/zh-CN.yml
new file mode 100644
index 0000000..0afd168
--- /dev/null
+++ b/resources/locales/jvn/cmds/version/zh-CN.yml
@@ -0,0 +1,20 @@
+version:
+ banner_title_line: JustEnoughVCS
+ banner_cmd_version: |
+ 命令行版本: %{cli_version} (%{build_time})
+ banner_core_version: |
+ 核心库版本: %{core_version}
+ no_banner_output: |
+ %{version}
+ no_banner_output_with_compile_info: |
+ 版本: %{version}
+
+ compile_info:
+ info: |
+ 编译信息:
+ __ 时间: [[cyan]]%{build_time}[[/]]
+ __ 目标: [[cyan]]%{target}[[/]]
+ __ 平台:[[cyan]]%{platform} - %{toolchain}[[/]]
+
+ __ 核心库:[[cyan]]%{core_branch}[[/]] (Commit: %{core_commit})
+ __ 命令行:[[cyan]]%{cli_branch}[[/]] (Commit: %{cli_commit})
diff --git a/resources/locales/jvn/en.yml b/resources/locales/jvn/en.yml
index ef3b273..f118566 100644
--- a/resources/locales/jvn/en.yml
+++ b/resources/locales/jvn/en.yml
@@ -1,3 +1,22 @@
+banner: |
+ _banner_begin
+ __ ████████ ████████
+ ██▒▒▒▒▒▒▒▒██ ██▒▒▒▒▒▒▒▒██
+ ██ ▒▒██ ██▒▒ ██ █████ ██ ██ ██████ █████
+ ██ ▒▒████████▒▒ ██ ▒▒▒██ ██ ██ ██████ ██████
+ ██ ▒▒▒▒▒▒▒▒ ██ ██ ██ ██ ███▒▒▒█ █▒▒▒▒█
+ ██ ██ ██ ██ ██ ███ ▒ ████ ▒
+ ██ ██ ██ ██ ██ ███ ▒████
+ ██ ████ ████ ██ ██ ▒██ ██▒ ███ ▒▒▒██
+ ██ ████ ████ ██ █ ██ ██ ██ ███ █ ██ ██
+ ██ ████ ████ ██ █ ██ ▒████▒ ▒██████ ██████
+ ██ ▒▒▒▒ ▒▒▒▒ █ ██ ▒████ ▒██▒ ██████ ▒████▒
+ ██ ██ ██ ▒▒▒▒ ▒▒ ▒▒▒▒▒▒ ▒▒▒▒
+ ██ ██████████ ██
+ ██ ██ %{banner_line_1}
+ __ ████████████████████████████████ %{banner_line_2}
+ __ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ %{banner_line_3}
+
process_error:
no_matching_command: |
No matching command found!
@@ -323,6 +342,7 @@ verbose:
disable_helpdoc: Helpdoc Viewer disabled
setup_i18n: Setting language to `%{lang}`
setup_renderer: Setting renderer to `%{renderer}`
+ redirect_to_version_command: Redirecting to `version` command
no_error_logs: Disabling error output
help: Help flag entered, command will not be executed
confirmed: Confirmation flag entered, all commands will run without confirmation
diff --git a/resources/locales/jvn/zh-CN.yml b/resources/locales/jvn/zh-CN.yml
index ca8a52e..8a7bdea 100644
--- a/resources/locales/jvn/zh-CN.yml
+++ b/resources/locales/jvn/zh-CN.yml
@@ -321,6 +321,7 @@ verbose:
disable_helpdoc: 帮助文档查看器已禁用
setup_i18n: 设置语言为 `%{lang}`
setup_renderer: 设置渲染器为 `%{renderer}`
+ redirect_to_version_command: 重定向至 `version` 命令
no_error_logs: 禁用错误输出
help: 帮助符号已输入,将不会执行命令
confirmed: 确认符号已输入,所有命令将无需确认即可运行
diff --git a/src/bin/jvn.rs b/src/bin/jvn.rs
index c2ae5ec..b051c51 100644
--- a/src/bin/jvn.rs
+++ b/src/bin/jvn.rs
@@ -89,8 +89,13 @@ async fn main() {
// Other flags
let no_error_logs = special_flag!(args, "--no-error-logs");
let help = special_flag!(args, "--help") || special_flag!(args, "-h");
+ let version = special_flag!(args, "--version") || special_flag!(args, "-v");
let confirmed = special_flag!(args, "--confirm") || special_flag!(args, "-C");
+ if version {
+ args.insert(0, "version".to_string());
+ trace!("{}", t!("verbose.redirect_to_version_command"));
+ }
if no_error_logs {
trace!("{}", t!("verbose.no_error_logs"));
}
diff --git a/src/cmds/arg/version.rs b/src/cmds/arg/version.rs
new file mode 100644
index 0000000..5e7edbe
--- /dev/null
+++ b/src/cmds/arg/version.rs
@@ -0,0 +1,8 @@
+#[derive(clap::Parser)]
+pub struct JVVersionArgument {
+ #[arg(short = 'c', long = "with-compile-info")]
+ pub with_compile_info: bool,
+
+ #[arg(long)]
+ pub no_banner: bool,
+}
diff --git a/src/cmds/cmd/version.rs b/src/cmds/cmd/version.rs
new file mode 100644
index 0000000..7a2e45b
--- /dev/null
+++ b/src/cmds/cmd/version.rs
@@ -0,0 +1,55 @@
+use crate::{
+ cmd_output,
+ cmds::{
+ arg::version::JVVersionArgument, collect::compile_info::JVCompileInfoCollect,
+ converter::version_in_out::JVVersionInputOutputConverter, r#in::version::JVVersionInput,
+ out::version::JVVersionOutput,
+ },
+ data::compile_info::CompileInfo,
+ systems::{
+ cmd::{
+ cmd_system::JVCommandContext,
+ errors::{CmdExecuteError, CmdPrepareError},
+ },
+ helpdoc::helpdoc_viewer,
+ },
+};
+use cmd_system_macros::exec;
+use just_enough_vcs::data::compile_info::CoreCompileInfo;
+use std::any::TypeId;
+
+pub struct JVVersionCommand;
+type Cmd = JVVersionCommand;
+type Arg = JVVersionArgument;
+type In = JVVersionInput;
+type Collect = JVCompileInfoCollect;
+
+async fn help_str() -> String {
+ helpdoc_viewer::display("commands/version").await;
+ String::new()
+}
+
+async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
+ Ok(JVVersionInput {
+ show_compile_info: args.with_compile_info,
+ show_banner: !args.no_banner,
+ })
+}
+
+async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
+ Ok(JVCompileInfoCollect {
+ compile_info: CompileInfo::default(),
+ compile_info_core: CoreCompileInfo::default(),
+ })
+}
+
+#[exec]
+async fn exec(
+ input: In,
+ collect: Collect,
+) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> {
+ let output = JVVersionInputOutputConverter::merge_to_output(input, collect);
+ cmd_output!(JVVersionOutput => output)
+}
+
+crate::command_template!();
diff --git a/src/cmds/collect/compile_info.rs b/src/cmds/collect/compile_info.rs
new file mode 100644
index 0000000..1f33660
--- /dev/null
+++ b/src/cmds/collect/compile_info.rs
@@ -0,0 +1,7 @@
+use crate::data::compile_info::CompileInfo;
+use just_enough_vcs::data::compile_info::CoreCompileInfo;
+
+pub struct JVCompileInfoCollect {
+ pub compile_info: CompileInfo,
+ pub compile_info_core: CoreCompileInfo,
+}
diff --git a/src/cmds/converter/version_in_out.rs b/src/cmds/converter/version_in_out.rs
new file mode 100644
index 0000000..34d243b
--- /dev/null
+++ b/src/cmds/converter/version_in_out.rs
@@ -0,0 +1,20 @@
+use crate::cmds::{
+ collect::compile_info::JVCompileInfoCollect, r#in::version::JVVersionInput,
+ out::version::JVVersionOutput,
+};
+
+pub struct JVVersionInputOutputConverter;
+
+impl JVVersionInputOutputConverter {
+ pub fn merge_to_output(
+ input: JVVersionInput,
+ collect: JVCompileInfoCollect,
+ ) -> JVVersionOutput {
+ JVVersionOutput {
+ show_compile_info: input.show_compile_info,
+ show_banner: input.show_banner,
+ compile_info: collect.compile_info,
+ compile_info_core: collect.compile_info_core,
+ }
+ }
+}
diff --git a/src/cmds/in/version.rs b/src/cmds/in/version.rs
new file mode 100644
index 0000000..d167268
--- /dev/null
+++ b/src/cmds/in/version.rs
@@ -0,0 +1,4 @@
+pub struct JVVersionInput {
+ pub show_compile_info: bool,
+ pub show_banner: bool,
+}
diff --git a/src/cmds/out/version.rs b/src/cmds/out/version.rs
new file mode 100644
index 0000000..fcbd90c
--- /dev/null
+++ b/src/cmds/out/version.rs
@@ -0,0 +1,10 @@
+use crate::data::compile_info::CompileInfo;
+use just_enough_vcs::data::compile_info::CoreCompileInfo;
+
+#[derive(serde::Serialize)]
+pub struct JVVersionOutput {
+ pub show_compile_info: bool,
+ pub show_banner: bool,
+ pub compile_info: CompileInfo,
+ pub compile_info_core: CoreCompileInfo,
+}
diff --git a/src/cmds/renderer/version.rs b/src/cmds/renderer/version.rs
new file mode 100644
index 0000000..cc76636
--- /dev/null
+++ b/src/cmds/renderer/version.rs
@@ -0,0 +1,92 @@
+use cli_utils::display::markdown::Markdown;
+use render_system_macros::result_renderer;
+use rust_i18n::t;
+
+use crate::{
+ cmds::out::version::JVVersionOutput,
+ r_println,
+ systems::{cmd::errors::CmdRenderError, render::renderer::JVRenderResult},
+};
+
+#[result_renderer(JVVersionRenderer)]
+pub async fn render(data: &JVVersionOutput) -> Result<JVRenderResult, CmdRenderError> {
+ let mut r = JVRenderResult::default();
+
+ if data.show_banner {
+ draw_banner(&mut r, data)
+ } else {
+ draw_version(&mut r, data);
+ }
+
+ if data.show_compile_info {
+ draw_compile_infos(&mut r, data);
+ }
+
+ Ok(r)
+}
+
+fn draw_banner(r: &mut JVRenderResult, data: &JVVersionOutput) {
+ let banner_str = t!(
+ "banner",
+ banner_line_1 = t!("version.banner_title_line").trim(),
+ banner_line_2 = t!(
+ "version.banner_cmd_version",
+ cli_version = data.compile_info.cli_version,
+ build_time = data.compile_info.date
+ )
+ .trim(),
+ banner_line_3 = t!(
+ "version.banner_core_version",
+ core_version = data.compile_info_core.vcs_version
+ )
+ .trim()
+ );
+ let trimmed_banner_str = banner_str
+ .trim_start_matches("_banner_begin")
+ .trim_matches('\n');
+ r_println!(r, "{}", trimmed_banner_str.to_string().markdown())
+}
+
+fn draw_version(r: &mut JVRenderResult, data: &JVVersionOutput) {
+ if data.show_compile_info {
+ r_println!(
+ r,
+ "{}",
+ t!(
+ "version.no_banner_output_with_compile_info",
+ version = data.compile_info.cli_version
+ )
+ .trim()
+ )
+ } else {
+ r_println!(
+ r,
+ "{}",
+ t!(
+ "version.no_banner_output",
+ version = data.compile_info.cli_version
+ )
+ .trim()
+ )
+ }
+}
+
+fn draw_compile_infos(r: &mut JVRenderResult, data: &JVVersionOutput) {
+ r_println!(
+ r,
+ "\n{}",
+ t!(
+ "version.compile_info.info",
+ build_time = data.compile_info.date,
+ target = data.compile_info.target,
+ platform = data.compile_info.platform,
+ toolchain = data.compile_info.toolchain,
+ core_branch = data.compile_info_core.build_branch,
+ cli_branch = data.compile_info.build_branch,
+ core_commit = &data.compile_info_core.build_commit[..7],
+ cli_commit = &data.compile_info.build_commit[..7]
+ )
+ .to_string()
+ .markdown()
+ );
+}
diff --git a/templates/compile_info.rs.template b/templates/compile_info.rs.template
index fcaaf63..d06f9b1 100644
--- a/templates/compile_info.rs.template
+++ b/templates/compile_info.rs.template
@@ -1,3 +1,4 @@
+#[derive(serde::Serialize)]
pub struct CompileInfo {
pub date: String,
pub target: String,