summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-10 09:25:17 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-10 09:25:17 +0800
commit4a8f272e7c72205707990fa0a9eab4fe57e12c7d (patch)
tree2508124eca3acb38b8ac57b0e2c10308ea2b43aa
parentb9e1964bdf75c2e06786a79426d41f0516de68b4 (diff)
Add helpful error tips for common workspace issues
-rw-r--r--locales/help_docs/en.yml16
-rw-r--r--locales/help_docs/zh-CN.yml14
-rw-r--r--src/bin/jv.rs57
-rw-r--r--src/bin/jvv.rs5
4 files changed, 86 insertions, 6 deletions
diff --git a/locales/help_docs/en.yml b/locales/help_docs/en.yml
index 07ff900..746fe4c 100644
--- a/locales/help_docs/en.yml
+++ b/locales/help_docs/en.yml
@@ -155,6 +155,22 @@ jv:
Target - %{build_target}
Platform - %{build_platform} - %{build_toolchain}
+ tip:
+ not_workspace: |
+ Not in workspace directory.
+ Use `jv create <name>` or `jv init` to create workspace
+
+ no_account: |
+ No accounts registered on this computer.
+ Use `jv account add <account_name>` to create account
+
+ no_account_set: |
+ Current workspace account is `unknown`, meaning no account is set
+ Use `jv as <account_name>` to set account for workspace
+
+ account_not_exist: |
+ The account `%{account}` set for the current workspace is not registered on your computer
+
help: |
**JustEnoughVCS**
This program connects to upstream vaults to synchronize and commit changes to local workspace files for collaborative work.
diff --git a/locales/help_docs/zh-CN.yml b/locales/help_docs/zh-CN.yml
index 42795d2..a7a5be1 100644
--- a/locales/help_docs/zh-CN.yml
+++ b/locales/help_docs/zh-CN.yml
@@ -149,6 +149,20 @@ jv:
目标:%{build_target}
平台:%{build_platform} - %{build_toolchain}
+ tip:
+ not_workspace: |
+ 当前不在工作区目录,您可使用 `jv create <名称>` 或 `jv init` 创建工作区
+
+ no_account: |
+ 您的计算机没有任何账户注册,可使用 `jv account add <账户名称>` 以创建账户
+
+ no_account_set: |
+ 当前工作区的账户为 `unknown`,这意味着您并未设置账户
+ 使用 `jv as <账户名称>` 来为工作区指定账户
+
+ account_not_exist: |
+ 当前工作区设置的账户 `%{account}` 并未注册至您的计算机
+
help: |
**JustEnoughVCS 本地工作区命令**
该程序将连接至上游库,用以同步、提交本地工作区文件的变化,以供协同创作
diff --git a/src/bin/jv.rs b/src/bin/jv.rs
index eda905e..9aea225 100644
--- a/src/bin/jv.rs
+++ b/src/bin/jv.rs
@@ -40,8 +40,9 @@ use just_enough_vcs_cli::{
data::compile_info::CompileInfo,
utils::{
display::{SimpleTable, size_str},
+ env::current_locales,
+ fs::move_across_partitions,
input::{confirm_hint, confirm_hint_or, input_with_editor},
- lang_selector::current_locales,
md_colored::md,
socket_addr_helper,
},
@@ -470,6 +471,58 @@ async fn main() {
let Ok(parser) = JustEnoughVcsWorkspace::try_parse() else {
eprintln!("{}", md(t!("jv.fail.parse.parser_failed")).bright_red());
+
+ // Tips
+ // Guide to create
+ {
+ // Check if workspace exist
+ let Some(_local_dir) = current_local_path() else {
+ println!();
+ println!("{}", t!("jv.tip.not_workspace").trim().bright_yellow());
+ return;
+ };
+
+ // Check if account list is not empty
+ let Some(dir) = UserDirectory::current_doc_dir() else {
+ return;
+ };
+
+ if let Ok(ids) = dir.account_ids() {
+ if ids.len() < 1 {
+ println!();
+ println!("{}", t!("jv.tip.no_account").trim().bright_yellow());
+ return;
+ }
+ }
+
+ // Check if the workspace has a registered account (account = unknown)
+ if let Some(local_cfg) = LocalConfig::read().await.ok() {
+ if local_cfg.current_account() == "unknown" {
+ println!();
+ println!("{}", t!("jv.tip.no_account_set").trim().bright_yellow());
+ } else {
+ if dir
+ .account_ids()
+ .ok()
+ .map(|ids| !ids.contains(&local_cfg.current_account()))
+ .unwrap_or(false)
+ {
+ println!();
+ println!(
+ "{}",
+ t!(
+ "jv.tip.account_not_exist",
+ account = local_cfg.current_account()
+ )
+ .trim()
+ .bright_yellow()
+ );
+ return;
+ }
+ }
+ }
+ }
+
return;
};
@@ -1371,7 +1424,7 @@ async fn jv_account_move_key(user_dir: UserDirectory, args: MoveKeyToAccountArgs
};
// Rename key file
- match fs::rename(
+ match move_across_partitions(
args.key_path,
user_dir.account_private_key_path(&args.account_name),
)
diff --git a/src/bin/jvv.rs b/src/bin/jvv.rs
index 9f80e0e..1bb461c 100644
--- a/src/bin/jvv.rs
+++ b/src/bin/jvv.rs
@@ -18,10 +18,7 @@ use just_enough_vcs::{
};
use just_enough_vcs_cli::{
data::compile_info::CompileInfo,
- utils::{
- build_env_logger::build_env_logger, display::size_str, lang_selector::current_locales,
- md_colored::md,
- },
+ utils::{display::size_str, env::current_locales, logger::build_env_logger, md_colored::md},
};
use log::{error, info};
use rust_i18n::{set_locale, t};