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
54
55
56
57
58
59
60
use owo_colors::OwoColorize;
use structopt::StructOpt;

macro_rules! subcommands {
    ($($ident:ident),* $(,)?) => {
        $(
            mod $ident;
            pub use $ident::*;
        )*
    };
}

subcommands!{
    new,
    build,
}

mod error;
pub use error::Error;


#[derive(StructOpt)]
#[structopt(bin_name = "cargo")]
pub enum Args {
    Mextk(SubCommands),
}

#[derive(StructOpt)]
pub enum SubCommands {
    #[structopt(help = "Create a new mod from the mextk template")]
    New {
        name: String,
    },
    
    #[structopt(help = "Build the current crate targetting MexTK")]
    Build {
        #[structopt(long)]
        debug: bool,
    },
}

pub fn main(args: Args) -> Result<(), Error> {
    let Args::Mextk(command) = args;

    match command {
        SubCommands::New { name } => new(&name),
        SubCommands::Build { debug } => {
            let output = build(debug)?;

            println!(
                "{}",
                format!("Object file built to {}", output.display())
                    .bright_green()
                    .bold()
            );

            Ok(())
        },
    }
}