summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--resources/helpdoc/commands/workspace.en.md11
-rw-r--r--resources/helpdoc/commands/workspace.zh-CN.md11
-rw-r--r--resources/helpdoc/commands/workspace/here.en.md4
-rw-r--r--resources/helpdoc/commands/workspace/here.zh-CN.md4
-rw-r--r--resources/locales/jvn/converters/space_error/en.yml4
-rw-r--r--resources/locales/jvn/converters/space_error/zh-CN.yml4
-rw-r--r--src/cmds/cmd/workspace_here.rs50
-rw-r--r--src/cmds/converter/space_error.rs22
8 files changed, 110 insertions, 0 deletions
diff --git a/resources/helpdoc/commands/workspace.en.md b/resources/helpdoc/commands/workspace.en.md
index 183a2d8..19a9609 100644
--- a/resources/helpdoc/commands/workspace.en.md
+++ b/resources/helpdoc/commands/workspace.en.md
@@ -19,3 +19,14 @@ jvn workspace sheet <arguments: ?>
> You can use the following to query detailed usage examples
> `jvn helpdoc commands/workspace/sheet`
+
+### Operate ID Alias
+Operate or read the `ID alias mapping` under the _current workspace_
+jvn workspace alias <arguments: ?>
+
+> You can use the following to query detailed usage examples
+> `jvn helpdoc commands/workspace/alias`
+
+### Query Workspace Directory
+Print the directory of the _current workspace_
+jvn workspace here
diff --git a/resources/helpdoc/commands/workspace.zh-CN.md b/resources/helpdoc/commands/workspace.zh-CN.md
index 4f3d537..6bcd32b 100644
--- a/resources/helpdoc/commands/workspace.zh-CN.md
+++ b/resources/helpdoc/commands/workspace.zh-CN.md
@@ -19,3 +19,14 @@ jvn workspace sheet <参数: ?>
> 您可以使用如下查询详细用例
> `jvn helpdoc commands/workspace/sheet`
+
+### 操作 ID 别名
+操作或读取_当前工作区_下的 `ID 别名映射`
+jvn workspace alias <参数: ?>
+
+> 您可以使用如下查询详细用例
+> `jvn helpdoc commands/workspace/alias`
+
+### 查询工作区所在目录
+打印_当前工作区_的目录
+jvn workspace here
diff --git a/resources/helpdoc/commands/workspace/here.en.md b/resources/helpdoc/commands/workspace/here.en.md
new file mode 100644
index 0000000..8cc0b01
--- /dev/null
+++ b/resources/helpdoc/commands/workspace/here.en.md
@@ -0,0 +1,4 @@
+> Print the directory of the `current workspace`
+
+## Usage
+jvn workspace here
diff --git a/resources/helpdoc/commands/workspace/here.zh-CN.md b/resources/helpdoc/commands/workspace/here.zh-CN.md
new file mode 100644
index 0000000..b1b569e
--- /dev/null
+++ b/resources/helpdoc/commands/workspace/here.zh-CN.md
@@ -0,0 +1,4 @@
+> 打印 `当前工作区` 的目录
+
+## 使用
+jvn workspace here
diff --git a/resources/locales/jvn/converters/space_error/en.yml b/resources/locales/jvn/converters/space_error/en.yml
new file mode 100644
index 0000000..7554416
--- /dev/null
+++ b/resources/locales/jvn/converters/space_error/en.yml
@@ -0,0 +1,4 @@
+space_error:
+ space_not_found: Space not found
+ path_fmt_error: |
+ Path format error: %{error}
diff --git a/resources/locales/jvn/converters/space_error/zh-CN.yml b/resources/locales/jvn/converters/space_error/zh-CN.yml
new file mode 100644
index 0000000..b402155
--- /dev/null
+++ b/resources/locales/jvn/converters/space_error/zh-CN.yml
@@ -0,0 +1,4 @@
+space_error:
+ space_not_found: 空间未找到
+ path_fmt_error: |
+ 路径格式错误: %{error}
diff --git a/src/cmds/cmd/workspace_here.rs b/src/cmds/cmd/workspace_here.rs
new file mode 100644
index 0000000..dde5bab
--- /dev/null
+++ b/src/cmds/cmd/workspace_here.rs
@@ -0,0 +1,50 @@
+use crate::{
+ cmd_output,
+ cmds::{
+ arg::empty::JVEmptyArgument, collect::workspace::JVWorkspaceCollect,
+ converter::space_error::JVSpaceErrorConverter, r#in::empty::JVEmptyInput,
+ out::path::JVPathOutput,
+ },
+ systems::{
+ cmd::{
+ cmd_system::{AnyOutput, JVCommandContext},
+ errors::{CmdExecuteError, CmdPrepareError},
+ },
+ helpdoc::helpdoc_viewer,
+ },
+};
+use cmd_system_macros::exec;
+use just_enough_vcs::system::workspace::workspace::manager::WorkspaceManager;
+
+pub struct JVWorkspaceHereCommand;
+type Cmd = JVWorkspaceHereCommand;
+type Arg = JVEmptyArgument;
+type In = JVEmptyInput;
+type Collect = JVWorkspaceCollect;
+
+async fn help_str() -> String {
+ helpdoc_viewer::display("commands/workspace_here").await;
+ String::new()
+}
+
+async fn prepare(_args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
+ Ok(JVEmptyInput)
+}
+
+async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
+ Ok(JVWorkspaceCollect {
+ manager: WorkspaceManager::new(),
+ })
+}
+
+#[exec]
+async fn exec(_input: In, collect: Collect) -> Result<AnyOutput, CmdExecuteError> {
+ let path = collect
+ .manager
+ .get_space()
+ .space_dir_current()
+ .map_err(JVSpaceErrorConverter::to_exec_error)?;
+ cmd_output!(JVPathOutput => JVPathOutput { path })
+}
+
+crate::command_template!();
diff --git a/src/cmds/converter/space_error.rs b/src/cmds/converter/space_error.rs
new file mode 100644
index 0000000..4ff7e7e
--- /dev/null
+++ b/src/cmds/converter/space_error.rs
@@ -0,0 +1,22 @@
+use crate::systems::cmd::errors::CmdExecuteError;
+use just_enough_vcs::system::space::error::SpaceError;
+use rust_i18n::t;
+
+pub struct JVSpaceErrorConverter;
+
+impl JVSpaceErrorConverter {
+ pub fn to_exec_error(err: SpaceError) -> CmdExecuteError {
+ match err {
+ SpaceError::SpaceNotFound => {
+ CmdExecuteError::Error(t!("space_error.space_not_found").trim().to_string())
+ }
+ SpaceError::PathFormatError(path_format_error) => CmdExecuteError::Error(
+ t!("space_error.path_fmt_error", error = path_format_error)
+ .trim()
+ .to_string(),
+ ),
+ SpaceError::Io(error) => CmdExecuteError::Io(error),
+ SpaceError::Other(msg) => CmdExecuteError::Error(msg),
+ }
+ }
+}