diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2023-11-28 20:06:41 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2023-11-28 20:06:41 +0100 |
| commit | fe76d91f33b2441de87597ae5885ea9005f35b1c (patch) | |
| tree | bda08242444d91dbf55e5e96233ae826c5e4e376 /crates/cli/bin.rs | |
| parent | 1256c4248d2a3a9f73c2a14d997a337ba0eee2b4 (diff) | |
refactor: seperate cli crate
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/cli/bin.rs')
| -rw-r--r-- | crates/cli/bin.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/cli/bin.rs b/crates/cli/bin.rs new file mode 100644 index 0000000..4e85481 --- /dev/null +++ b/crates/cli/bin.rs @@ -0,0 +1,43 @@ +use argh::FromArgs; +use color_eyre::eyre::Result; +use tinywasm::{self, Module}; + +#[derive(FromArgs)] +/// TinyWasm CLI +struct TinyWasmCli { + #[argh(subcommand)] + nested: TinyWasmSubcommand, +} + +#[derive(FromArgs)] +#[argh(subcommand)] +enum TinyWasmSubcommand { + Run(Run), +} + +#[derive(FromArgs)] +/// run a wasm file +#[argh(subcommand, name = "run")] +struct Run { + /// wasm file to run + #[argh(positional)] + wasm_file: String, +} + +fn main() -> Result<()> { + let args: TinyWasmCli = argh::from_env(); + + match args.nested { + TinyWasmSubcommand::Run(Run { wasm_file }) => { + let wasm = std::fs::read(wasm_file).unwrap(); + run(&wasm)?; + Ok(()) + } + } +} + +fn run(wasm: &[u8]) -> Result<()> { + let module = Module::new(wasm)?; + println!("{:#?}", module); + Ok(()) +} |
