summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-05 16:43:03 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-05 16:43:03 +0800
commit81103c096c6709937b430c53d32f91b9a73c6355 (patch)
tree783921f0abf7a289baee6c3fb347572c5259b16d
parentac6dd5db0c3a0880f7dd3d5c303c19d078c2ad3b (diff)
Add sheet drop functionality and improve sheet listing
- Implement `jv sheet drop` command with confirmation and error handling - Add restore confirmation when creating sheets that already exist as orphaned sheets - Enhance `jv sheet list` with --others and --all flags to show different sheet views - Update help text and localization files for new functionality
-rw-r--r--locales/help_docs/en.yml44
-rw-r--r--locales/help_docs/zh-CN.yml44
-rw-r--r--src/bin/jv.rs130
3 files changed, 203 insertions, 15 deletions
diff --git a/locales/help_docs/en.yml b/locales/help_docs/en.yml
index b899cdf..9bc5806 100644
--- a/locales/help_docs/en.yml
+++ b/locales/help_docs/en.yml
@@ -371,6 +371,16 @@ jv:
direct: |
Do you want to direct the current local workspace to the upstream vault %{upstream}?
+ sheet:
+ make:
+ restore: |
+ Sheet `%{sheet_name}` is no holder. Take ownership?
+ If not, use a different name to create a sheet.
+
+ drop: |
+ Are you sure you want to drop sheet `%{sheet_name}`?
+ After this, you will not be able to work in the sheet!
+
fail:
path_not_found: |
The directory `%{path}` cannot be found!
@@ -393,6 +403,7 @@ jv:
remove: Failed to remove account `%{account}`, please check if the account exists.
list: Failed to get account list!
not_found: Cannot find account `%{account}`!
+ as: Failed to set current account, please ensure the current sheet has been exited
init_create_dir_not_empty: |
The current directory is not empty!
@@ -457,10 +468,9 @@ jv:
other_sheet_item_no_holder: |
%{number}. %{name} (NO HOLDER)
tip_has_sheet: |
- You can use `jv use <SHEET_NAME>` to start working
+ You are not on any sheet, you can use `jv use <SHEET_NAME>` to use a sheet
tip_no_sheet: |
- **YOU HAVE NO SHEETS**
- You can use `jv sheet make <SHEET_NAME>` to create a new sheet
+ You don't have any sheets, you can use `jv make <SHEET_NAME>` to create a new sheet
result:
common:
@@ -496,7 +506,35 @@ jv:
success: |
Successfully created sheet `%{name}`!
Upstream changed,use `jv update` to get the latest information
+
+ success_restore: |
+ Successfully restored sheet `%{name}`!
+ Upstream changed,use `jv update` to get the latest information
+
sheet_already_exists: |
Sheet `%{name}` already exists!
+
sheet_creation_failed: |
Sheet creation failed: `%{error}`
+
+ drop:
+ success: |
+ Successfully dropped sheet `%{name}`!
+ Upstream changed, use `jv update` to sync to latest information
+ **Tip**: You can use `jv make %{name}` to restore this sheet
+
+ sheet_in_use: |
+ Sheet `%{name}` is in use, cannot drop!
+ **Tip**: Please use `jv exit` to exit current sheet first
+
+ sheet_not_exists: |
+ Sheet `%{name}` does not exist!
+
+ sheet_drop_failed: |
+ Failed to drop sheet: %{err}
+
+ no_holder: |
+ Sheet `%{name}` has no holder!
+
+ not_owner: |
+ You are not the holder of sheet `%{name}`, cannot drop it!
diff --git a/locales/help_docs/zh-CN.yml b/locales/help_docs/zh-CN.yml
index effad0b..7b6c653 100644
--- a/locales/help_docs/zh-CN.yml
+++ b/locales/help_docs/zh-CN.yml
@@ -378,6 +378,15 @@ jv:
direct: |
是否需要将当前本地工作区定向到上游库 %{upstream}?
+ sheet:
+ make:
+ restore: |
+ 似乎 `%{sheet_name}` 是一张无人认领的表,是否拿到它的所有权?
+ 如果您不想拿到该表,请使用别的名称建立表
+
+ drop: |
+ 是否要放弃表 `%{sheet_name}` 的所有权,此后,您将无法在表中工作!
+
fail:
path_not_found: |
您给出的目录 `%{path}` 无法找到!
@@ -401,6 +410,7 @@ jv:
list: 获取账户列表失败!
move_key: 将该私钥移动至账户目录失败!
not_found: 无法找到账户 `%{account}`!
+ as: 设置当前账户失败,请确保当前表已退出
init_create_dir_not_empty: |
当前目录并不是空的!
@@ -453,7 +463,7 @@ jv:
sheet:
list:
your_sheet: |
- **你的表**:
+ **您的表**:
your_sheet_item: |
%{number}. %{name}
your_sheet_item_use: |
@@ -465,10 +475,10 @@ jv:
other_sheet_item_no_holder: |
%{number}. %{name}(无人认领)
tip_has_sheet: |
- 你可以使用 `jv use <表名>` 开始工作
+ 您不在任何一张表,可使用 `jv use <表名>` 使用一张表
tip_no_sheet: |
**没有可以编辑的表!**
- 你可以使用 `jv sheet make <表名>` 创建一张新表
+ 您没有任何一张表,可使用 `jv make <表名>` 创建一张新表
result:
common:
@@ -503,7 +513,35 @@ jv:
success: |
成功创建表 `%{name}`!
上游信息已变更,请使用 `jv update` 同步至最新信息
+
+ success_restore: |
+ 成功恢复表 `%{name}` 的所有权!
+ 上游信息已变更,请使用 `jv update` 同步至最新信息
+
sheet_already_exists: |
表 `%{name}` 已存在!
+
sheet_creation_failed: |
表创建失败:`%{err}`
+
+ drop:
+ success: |
+ 成功放弃表 `%{name}` 的所有权!
+ 上游信息已变更,请使用 `jv update` 同步至最新信息
+ **提示**:您可以使用 `jv make %{name}` 赎回该表
+
+ sheet_in_use: |
+ 表 `%{name}` 正在被使用中,无法放弃!
+ **提示**:请先 `jv exit` 退出当前表,再尝试该操作!
+
+ sheet_not_exists: |
+ 表 `%{name}` 不存在!
+
+ sheet_drop_failed: |
+ 放弃表失败:%{err}
+
+ no_holder: |
+ 表 `%{name}` 没有持有人!
+
+ not_owner: |
+ 您不是表 `%{name}` 的持有人,无法放弃该表!
diff --git a/src/bin/jv.rs b/src/bin/jv.rs
index 9a46cdf..168a7af 100644
--- a/src/bin/jv.rs
+++ b/src/bin/jv.rs
@@ -217,6 +217,14 @@ struct SheetListArgs {
/// Show help information
#[arg(short, long)]
help: bool,
+
+ /// 显示他人的表而不是自己的
+ #[arg(short, long)]
+ others: bool,
+
+ /// 显示所有的表
+ #[arg(short = 'A', long)]
+ all: bool,
}
#[derive(Parser, Debug)]
@@ -252,6 +260,10 @@ struct SheetDropArgs {
#[arg(short, long)]
help: bool,
+ /// Whether to skip confirmation
+ #[arg(short = 'C', long)]
+ confirm: bool,
+
/// Sheet name
sheet_name: String,
}
@@ -717,7 +729,7 @@ async fn jv_here(_args: HereArgs) {
todo!()
}
-async fn jv_sheet_list(_args: SheetListArgs) {
+async fn jv_sheet_list(args: SheetListArgs) {
let Some(_local_dir) = current_local_path() else {
eprintln!("{}", t!("jv.fail.workspace_not_found").trim());
return;
@@ -737,7 +749,7 @@ async fn jv_sheet_list(_args: SheetListArgs) {
let mut other_sheet_counts = 0;
// Print your sheets
- {
+ if !args.others && !args.all || !args.others {
println!("{}", md(t!("jv.success.sheet.list.your_sheet")));
let in_use = local_cfg.sheet_in_use();
for sheet in latest_info.my_sheets {
@@ -764,11 +776,13 @@ async fn jv_sheet_list(_args: SheetListArgs) {
}
your_sheet_counts += 1;
}
- println!();
}
// Print other sheets
- {
+ if args.others || args.all {
+ if args.all {
+ println!();
+ }
println!("{}", md(t!("jv.success.sheet.list.other_sheet")));
for sheet in latest_info.other_sheets {
if let Some(holder) = sheet.holder_name {
@@ -793,11 +807,11 @@ async fn jv_sheet_list(_args: SheetListArgs) {
}
other_sheet_counts += 1;
}
- println!();
}
- // Print tips
- {
+ // If not use any sheets, print tips
+ if local_cfg.sheet_in_use().is_none() {
+ println!();
if your_sheet_counts > 0 {
println!("{}", md(t!("jv.success.sheet.list.tip_has_sheet")));
} else {
@@ -867,6 +881,28 @@ async fn jv_sheet_make(args: SheetMakeArgs) {
None => return,
};
+ let latest_info = match LatestInfo::read().await {
+ Ok(info) => info,
+ Err(_) => {
+ eprintln!("{}", t!("jv.fail.read_cfg"));
+ return;
+ }
+ };
+
+ if latest_info
+ .other_sheets
+ .iter()
+ .any(|sheet| sheet.sheet_name == sheet_name)
+ {
+ eprintln!(
+ "{}",
+ md(t!("jv.confirm.sheet.make.restore", sheet_name = sheet_name))
+ );
+ if !confirm_hint(t!("common.confirm")).await {
+ return;
+ }
+ }
+
match proc_make_sheet_action(&pool, ctx, sheet_name.clone()).await {
Ok(r) => match r {
MakeSheetActionResult::Success => {
@@ -875,6 +911,15 @@ async fn jv_sheet_make(args: SheetMakeArgs) {
md(t!("jv.result.sheet.make.success", name = sheet_name))
)
}
+ MakeSheetActionResult::SuccessRestore => {
+ eprintln!(
+ "{}",
+ md(t!(
+ "jv.result.sheet.make.success_restore",
+ name = sheet_name
+ ))
+ )
+ }
MakeSheetActionResult::AuthorizeFailed(e) => {
eprintln!("{}", md(t!("jv.result.common.authroize_failed", err = e)))
}
@@ -899,8 +944,75 @@ async fn jv_sheet_make(args: SheetMakeArgs) {
}
}
-async fn jv_sheet_drop(_args: SheetDropArgs) {
- todo!()
+async fn jv_sheet_drop(args: SheetDropArgs) {
+ let sheet_name = snake_case!(args.sheet_name);
+
+ if !args.confirm {
+ println!(
+ "{}",
+ t!("jv.confirm.sheet.drop", sheet_name = sheet_name).trim()
+ );
+ confirm_hint_or(t!("common.confirm"), || exit(1)).await;
+ }
+
+ let local_config = match precheck().await {
+ Some(config) => config,
+ None => return,
+ };
+
+ let (pool, ctx) = match build_pool_and_ctx(&local_config).await {
+ Some(result) => result,
+ None => return,
+ };
+
+ match proc_drop_sheet_action(&pool, ctx, sheet_name.clone()).await {
+ Ok(r) => match r {
+ DropSheetActionResult::Success => {
+ println!(
+ "{}",
+ md(t!("jv.result.sheet.drop.success", name = sheet_name))
+ )
+ }
+ DropSheetActionResult::SheetInUse => {
+ eprintln!(
+ "{}",
+ md(t!("jv.result.sheet.drop.sheet_in_use", name = sheet_name))
+ )
+ }
+ DropSheetActionResult::AuthorizeFailed(e) => {
+ eprintln!("{}", md(t!("jv.result.common.authroize_failed", err = e)))
+ }
+ DropSheetActionResult::SheetNotExists => {
+ eprintln!(
+ "{}",
+ md(t!(
+ "jv.result.sheet.drop.sheet_not_exists",
+ name = sheet_name
+ ))
+ )
+ }
+ DropSheetActionResult::SheetDropFailed(e) => {
+ eprintln!(
+ "{}",
+ md(t!("jv.result.sheet.drop.sheet_drop_failed", err = e))
+ )
+ }
+ DropSheetActionResult::NoHolder => {
+ eprintln!(
+ "{}",
+ md(t!("jv.result.sheet.drop.no_holder", name = sheet_name))
+ )
+ }
+ DropSheetActionResult::NotOwner => {
+ eprintln!(
+ "{}",
+ md(t!("jv.result.sheet.drop.not_owner", name = sheet_name))
+ )
+ }
+ _ => {}
+ },
+ Err(e) => handle_err(e),
+ }
}
async fn jv_track(_args: TrackFileArgs) {