summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-17 19:15:03 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-17 19:15:03 +0800
commite78eac0511bebe72e471346bb45d8b7436a52799 (patch)
tree762e6e4f8a35d985b7c0b3719c526beb5c82d7d6
parent0b2a864d85015e2f69f83d8be3d6a4e2ab10629f (diff)
Add error handling for sheet use command
-rw-r--r--locales/help_docs/en.yml9
-rw-r--r--locales/help_docs/zh-CN.yml9
-rw-r--r--src/bin/jv.rs29
3 files changed, 43 insertions, 4 deletions
diff --git a/locales/help_docs/en.yml b/locales/help_docs/en.yml
index 4997257..db143a1 100644
--- a/locales/help_docs/en.yml
+++ b/locales/help_docs/en.yml
@@ -533,6 +533,15 @@ jv:
analyze: |
Failed to analyze local workspace status!
+ use:
+ sheet_not_exists: |
+ Sheet `%{name}` does not exist!
+ **Tip**: Please use `jv update` to update workspace status
+
+ directory_not_empty: |
+ When no sheet is in use, the workspace should not contain any files!
+ **Tip**: Please ensure the workspace is clean before using `jv use <sheet_name>` to select and use a sheet
+
success:
account:
as: Successfully switched this workspace's account to `%{account}`
diff --git a/locales/help_docs/zh-CN.yml b/locales/help_docs/zh-CN.yml
index c35b6aa..a1dd4fe 100644
--- a/locales/help_docs/zh-CN.yml
+++ b/locales/help_docs/zh-CN.yml
@@ -540,6 +540,15 @@ jv:
analyze: |
分析本地工作区的状态失败!
+ use:
+ sheet_not_exists: |
+ 表 `%{name}` 不存在!
+ **提示**:请使用 `jv update` 更新工作区状态
+
+ directory_not_empty: |
+ 在没有使用表的时候,工作区不应该存在任何文件!
+ **提示**:请保证工作区是干净的,再使用 `jv use <表名>` 选择并使用一张表
+
success:
account:
as: 成功将此工作区的账户切换至 `%{account}`
diff --git a/src/bin/jv.rs b/src/bin/jv.rs
index 7507680..51f73dd 100644
--- a/src/bin/jv.rs
+++ b/src/bin/jv.rs
@@ -1474,16 +1474,37 @@ async fn jv_sheet_use(args: SheetUseArgs) {
return;
};
- match local_cfg.use_sheet(args.sheet_name).await {
+ match local_cfg.use_sheet(args.sheet_name.clone()).await {
Ok(_) => {
let Ok(_) = LocalConfig::write(&local_cfg).await else {
eprintln!("{}", t!("jv.fail.write_cfg").trim().red());
return;
};
}
- Err(e) => {
- handle_err(e.into());
- }
+ Err(e) => match e.kind() {
+ std::io::ErrorKind::AlreadyExists => {} // Already In Use
+ std::io::ErrorKind::NotFound => {
+ eprintln!(
+ "{}",
+ md(t!("jv.fail.use.sheet_not_exists", name = args.sheet_name)).red()
+ );
+ return;
+ }
+ std::io::ErrorKind::DirectoryNotEmpty => {
+ eprintln!(
+ "{}",
+ md(t!(
+ "jv.fail.use.directory_not_empty",
+ name = args.sheet_name
+ ))
+ .red()
+ );
+ return;
+ }
+ _ => {
+ handle_err(e.into());
+ }
+ },
}
}