summaryrefslogtreecommitdiff
path: root/src/cmds/cmd/helpdoc.rs
blob: 98e0309da70315ce0a36aad4350b3b3bbb46a3b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::{
    cmd_output,
    cmds::{
        arg::helpdoc::JVHelpdocArgument, collect::empty::JVEmptyCollect,
        r#in::helpdoc::JVHelpdocInput, out::none::JVNoneOutput,
    },
    systems::{
        cmd::{
            cmd_system::JVCommandContext,
            errors::{CmdExecuteError, CmdPrepareError},
        },
        helpdoc::{DEFAULT_HELPDOC, helpdoc_viewer},
    },
};
use cmd_system_macros::exec;
use std::any::TypeId;

pub struct JVHelpdocCommand;
type Cmd = JVHelpdocCommand;
type Arg = JVHelpdocArgument;
type In = JVHelpdocInput;
type Collect = JVEmptyCollect;

async fn help_str() -> String {
    helpdoc_viewer::display("commands/helpdoc").await;
    String::new()
}

async fn prepare(args: &Arg, ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
    Ok(JVHelpdocInput {
        name: args.doc_name.clone().unwrap_or(DEFAULT_HELPDOC.to_string()),
        lang: ctx.lang.clone(),
    })
}

async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
    Ok(JVEmptyCollect)
}

#[exec]
async fn exec(
    input: In,
    _collect: Collect,
) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> {
    helpdoc_viewer::display_with_lang(&input.name.as_str(), &input.lang.as_str()).await;
    cmd_output!(JVNoneOutput => JVNoneOutput)
}

crate::command_template!();