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
use anyhow::Result;
use clap::Parser;
mod commands;
pub mod template;
pub mod utils;

#[derive(Debug, Parser)]
#[clap(version)]
pub struct Opts {
    #[clap(subcommand)]
    pub command: Command,
}

#[derive(Debug, Parser)]
pub enum Command {
    /// Builds all collections from the workspace
    Build,
    /// Serves all collections from the workspace
    Serve,
    /// Runs the test suite for the workspace
    Test,
    /// Cleans all the temp files
    Clean,
    /// Initializes a new workspace
    Init {
        name: String,
    },
    /// Create a new collection in the workspace
    New {
        name: String,
    },
}

fn process_command(opts: Opts) -> Result<()> {
    match &opts.command {
        Command::Build => Ok(commands::build::run()),
        Command::Serve => Ok(commands::serve::run()),
        Command::Test => Ok(commands::test::run()),
        Command::Clean => Ok(commands::clean::run()),
        Command::Init { name } => Ok(commands::init::run(&name)),
        Command::New { name } => Ok(commands::new::run(&name)),
    }
}

pub fn entry(opts: Opts) -> Result<()>  {

    process_command(opts)
}