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
extern crate toml;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate structopt;
extern crate colored;
extern crate notify;
extern crate warp;

use structopt::StructOpt;

mod buildcmd;
mod error;
mod parse;
mod runcmd;
mod server;

#[derive(StructOpt)]
#[structopt(name = "cargo-ruukh")]
pub enum CargoRuukh {
    /// Compile the current Ruukh project for WASM target
    #[structopt(name = "build")]
    Build(buildcmd::BuildCommand),
    /// Build and execute src/lib.rs on browser
    #[structopt(name = "run")]
    Run(runcmd::RunCommand),
}

impl CargoRuukh {
    pub fn from_args(args: Vec<String>) -> CargoRuukh {
        CargoRuukh::from_iter(args)
    }

    pub fn exec(self) {
        let result = match self {
            CargoRuukh::Build(cmd) => cmd.exec(),
            CargoRuukh::Run(cmd) => cmd.exec(),
        };

        if let Err(err) = result {
            eprintln!("Error occurred: {}", err);
        }
    }
}