diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-26 15:55:10 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-26 15:55:10 +0800 |
| commit | fb2ffa849a2cf9251cc274ebea5daa9898579787 (patch) | |
| tree | 53b87ee60ba7c6ee7b001221855a6f3bff7e8526 /src/cmds/comp/workspace_sheet.rs | |
| parent | 4cb7c2e91d7dbde32de31e6ab48683d60212ec1d (diff) | |
Add shell completion system with descriptions and i18n support
Diffstat (limited to 'src/cmds/comp/workspace_sheet.rs')
| -rw-r--r-- | src/cmds/comp/workspace_sheet.rs | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/cmds/comp/workspace_sheet.rs b/src/cmds/comp/workspace_sheet.rs index 3162442..8318fbe 100644 --- a/src/cmds/comp/workspace_sheet.rs +++ b/src/cmds/comp/workspace_sheet.rs @@ -1,25 +1,39 @@ -use crate::systems::comp::context::CompletionContext; -use cli_utils::string_vec; +use comp_system_macros::{file_suggest, suggest}; use just_enough_vcs::system::workspace::workspace::manager::WorkspaceManager; +use rust_i18n::t; -pub fn comp(ctx: CompletionContext) -> Option<Vec<String>> { +use crate::systems::comp::{context::CompletionContext, result::CompletionResult}; + +pub fn comp(ctx: CompletionContext) -> CompletionResult { if ctx.current_word.starts_with('-') { - return Some(string_vec![ - "-A", - "--list-all", - "-p", - "--print-path", - "-n", - "--new", - "-d", - "--delete", - ]); + return suggest!( + "-A" = t!("workspace_sheet.comp.list_all").trim(), + "--list-all" = t!("workspace_sheet.comp.list_all").trim(), + "-p" = t!("workspace_sheet.comp.print_path").trim(), + "--print-path" = t!("workspace.sheet.comp.print_path").trim(), + "-n" = t!("workspace_sheet.comp.new").trim(), + "--new" = t!("workspace_sheet.comp.new").trim(), + "-d" = t!("workspace_sheet.comp.delete").trim(), + "--delete" = t!("workspace_sheet.comp.delete").trim() + ) + .into(); } if ctx.previous_word == "--new" || ctx.previous_word == "-n" { - return Some(vec![]); + return suggest!().into(); + } + + if ctx.previous_word == "--list-all" + || ctx.previous_word == "-A" + || ctx.previous_word == "--print-path" + || ctx.previous_word == "-p" + || ctx.previous_word == "--delete" + || ctx.previous_word == "-d" + { + let rt = tokio::runtime::Runtime::new().unwrap(); + let names = rt.block_on(WorkspaceManager::new().list_sheet_names()); + return names.into(); } - let rt = tokio::runtime::Runtime::new().unwrap(); - Some(rt.block_on(WorkspaceManager::new().list_sheet_names())) + file_suggest!() } |
