diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-12 19:04:12 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-12 19:04:12 +0800 |
| commit | 72c57380883a1c1cc796dea6d35048ab5bed5f53 (patch) | |
| tree | 936e04d2ec0f5bae54667beac6bf069208900a80 /src/systems/cmd | |
| parent | 9d812580557cdc343378816cd65678b8aa75d944 (diff) | |
Add helpdoc system with interactive viewer
Diffstat (limited to 'src/systems/cmd')
| -rw-r--r-- | src/systems/cmd/cmd_system.rs | 9 | ||||
| -rw-r--r-- | src/systems/cmd/macros.rs | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/systems/cmd/cmd_system.rs b/src/systems/cmd/cmd_system.rs index 67f5c7f..3ae4d5e 100644 --- a/src/systems/cmd/cmd_system.rs +++ b/src/systems/cmd/cmd_system.rs @@ -28,7 +28,7 @@ where Collect: Send, { /// Get help string for the command - fn get_help_str() -> String; + fn get_help_str() -> impl Future<Output = String> + Send; /// Run the command and convert the result into type-agnostic serialized information, /// then hand it over to the universal renderer for rendering. @@ -72,7 +72,10 @@ where // skip execution and directly render help information if ctx.help { let mut r = JVRenderResult::default(); - r_println!(r, "{}", Self::get_help_str()); + let help_str = Self::get_help_str().await; + if !help_str.is_empty() { + r_println!(r, "{}", help_str); + } return Ok(r); } @@ -112,7 +115,7 @@ where t = type_name::<Argument>() ) ); - return Err(CmdProcessError::ParseError(Self::get_help_str())); + return Err(CmdProcessError::ParseError(Self::get_help_str().await)); } }; diff --git a/src/systems/cmd/macros.rs b/src/systems/cmd/macros.rs index 093d178..e9af1ac 100644 --- a/src/systems/cmd/macros.rs +++ b/src/systems/cmd/macros.rs @@ -51,7 +51,7 @@ /// type Collect = JVCustomCollect; /// /// /// Return a string, rendered when the user needs help (command specifies `--help` or syntax error) -/// fn help_str() -> String { +/// async fn help_str() -> String { /// todo!() /// } /// @@ -97,7 +97,7 @@ /// type In = JVCustomInput; /// type Collect = JVCustomCollect; /// -/// fn help_str() -> String { +/// async fn help_str() -> String { /// todo!() /// } /// @@ -121,8 +121,8 @@ macro_rules! command_template { () => { impl $crate::systems::cmd::cmd_system::JVCommand<Arg, In, Collect> for Cmd { - fn get_help_str() -> String { - help_str() + async fn get_help_str() -> String { + help_str().await } async fn prepare( |
