-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.rs
More file actions
80 lines (72 loc) · 2.21 KB
/
main.rs
File metadata and controls
80 lines (72 loc) · 2.21 KB
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
use clap::{Parser, Subcommand};
use mrubyedge_cli::subcommands;
const LONG_VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
", using mruby/edge ",
mrubyedge::version!(),
);
#[derive(Parser)]
#[command(name = "mrbedge")]
#[command(about = "mruby/edge command line interface", long_about = None)]
#[command(version)]
#[command(long_version = LONG_VERSION)]
#[command(args_conflicts_with_subcommands = true)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
#[command(flatten)]
run_args: Option<subcommands::run::RunArgs>,
}
#[derive(Subcommand)]
enum Commands {
/// Run Ruby code or binary.
/// Run is invoked when rb/mrb file is directly passed to the command
Run(subcommands::run::RunArgs),
/// Start an interactive REPL (Read-Eval-Print Loop)
Repl(subcommands::repl::ReplArgs),
/// Generate WebAssembly binary from Ruby code
Wasm(subcommands::wasm::WasmArgs),
/// Compile Ruby script to mrb
CompileMrb(subcommands::compile_mrb::CompileMrbArgs),
/// Scaffold the package project with a wasm binary
Scaffold {
#[command(subcommand)]
scaffold_type: ScaffoldType,
},
}
#[derive(Subcommand)]
enum ScaffoldType {
/// Scaffold npm package
Npm,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
match cli.command {
Some(Commands::Run(args)) => {
subcommands::run::execute(args)?;
}
Some(Commands::Repl(args)) => {
subcommands::repl::execute(args)?;
}
Some(Commands::Wasm(args)) => {
subcommands::wasm::execute(args)?;
}
Some(Commands::CompileMrb(args)) => {
subcommands::compile_mrb::execute(args)?;
}
Some(Commands::Scaffold { scaffold_type }) => match scaffold_type {
ScaffoldType::Npm => {
subcommands::scaffold::execute_npm();
}
},
None => {
if let Some(args) = cli.run_args {
subcommands::run::execute(args)?;
} else {
eprintln!("No subcommand was used. Use --help for more information.");
std::process::exit(1);
}
}
}
Ok(())
}