wasmer_compiler_cli/
cli.rs1use crate::commands::Compile;
4use crate::commands::{Config, Validate};
5use crate::error::PrettyError;
6use anyhow::Result;
7
8use clap::{Parser, error::ErrorKind};
9
10#[derive(Parser)]
11#[clap(
12 name = "wasmer-compiler",
13 about = "WebAssembly standalone Compiler.",
14 author
15)]
16enum WasmerCLIOptions {
18 #[clap(name = "validate")]
20 Validate(Validate),
21
22 #[clap(name = "compile")]
24 Compile(Compile),
25
26 #[clap(name = "config")]
29 Config(Config),
30}
31
32impl WasmerCLIOptions {
33 fn execute(&self) -> Result<()> {
34 match self {
35 Self::Validate(validate) => validate.execute(),
36 Self::Compile(compile) => compile.execute(),
37 Self::Config(config) => config.execute(),
38 }
39 }
40}
41
42pub fn wasmer_main() {
44 #[cfg(windows)]
46 colored::control::set_virtual_terminal(true).unwrap();
47
48 let args = std::env::args().collect::<Vec<_>>();
56 let command = args.get(1);
57 let options = {
58 match command.unwrap_or(&"".to_string()).as_ref() {
59 "compile" | "config" | "help" | "inspect" | "validate" => WasmerCLIOptions::parse(),
60 _ => {
61 WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| {
62 match e.kind() {
63 ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(),
67 _ => WasmerCLIOptions::Compile(Compile::parse()),
68 }
69 })
70 }
71 }
72 };
73
74 PrettyError::report(options.execute());
75}