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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#[macro_use] extern crate failure_derive;
extern crate failure;
extern crate clap;
pub mod assets;
pub mod cargo;
pub mod error;
pub mod rustup;
use failure::Error;
use clap::{ App, Arg, SubCommand };
use cargo::*;
use rustup::setup;
use std::process::exit;
fn main() {
if let Err(e) = run() {
eprintln!("{}", e);
exit(1);
}
}
fn run() -> Result<(), Error> {
let matches = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.subcommand(
SubCommand::with_name("wasm")
.about("Commiting code and it's options")
.subcommand(
SubCommand::with_name("new")
.about("Setup the environment for a wasm project")
.arg(Arg::with_name("project_name")
.help("Name of the new wasm project")
.required(true)))
.subcommand(
SubCommand::with_name("build")
.about("Build the wasm project")
.arg(Arg::with_name("release")
.help("Make a release build")
.long("release")
.required(false))
.arg(Arg::with_name("output_dir")
.help("Path to output wasm file")
.takes_value(true)
.short("o")
.required(false)))
.subcommand(
SubCommand::with_name("run")
.about("Run the wasm project")
.arg(Arg::with_name("release")
.help("Run a release build")
.long("release")
.required(false))
.arg(Arg::with_name("PATH")
.help("Path to directory to run")
.required(false))
)
.subcommand(
SubCommand::with_name("setup")
.about("Setup the environment for a wasm project"))
)
.get_matches();
if let Some(matches) = matches.subcommand_matches("wasm") {
if let Some(matches) = matches.subcommand_matches("new") {
cargo_new(matches.value_of("project_name").unwrap())?;
} else if let Some(matches) = matches.subcommand_matches("build") {
let _release = matches.is_present("release");
// There's a bug is wasm-gc isn't run
cargo_build(true, matches.value_of("output_dir"))?;
} else if let Some(matches) = matches.subcommand_matches("run") {
let _release = matches.is_present("release");
// There's a bug is wasm-gc isn't run
cargo_run(true, matches.value_of("PATH"))?;
} else if let Some(_) = matches.subcommand_matches("setup") {
setup()?;
}
}
Ok(())
}