summaryrefslogtreecommitdiff
path: root/src/cmds/cmd/workspace_create.rs
blob: c5f8c8efd1bb4c9b6c6f887e118e48a8faa3aafc (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
50
51
52
53
use crate::{
    cmd_output,
    cmds::{
        arg::path::JVPathArgument, collect::empty::JVEmptyCollect,
        converter::workspace_operation_error::JVWorkspaceOperationErrorConverter,
        r#in::workspace_create::JVWorkspaceCreateInput, out::none::JVNoneOutput,
    },
    systems::{
        cmd::{
            cmd_system::JVCommandContext,
            errors::{CmdExecuteError, CmdPrepareError},
        },
        helpdoc::helpdoc_viewer,
    },
};
use cmd_system_macros::exec;
use just_enough_vcs::system::workspace::func::create_workspace;
use std::any::TypeId;

pub struct JVWorkspaceCreateCommand;
type Cmd = JVWorkspaceCreateCommand;
type Arg = JVPathArgument;
type In = JVWorkspaceCreateInput;
type Collect = JVEmptyCollect;

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

async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
    Ok(JVWorkspaceCreateInput {
        path: args.path.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> {
    create_workspace(input.path)
        .await
        .map_err(JVWorkspaceOperationErrorConverter::to_exec_error)?;

    cmd_output!(JVNoneOutput => JVNoneOutput)
}

crate::command_template!();