From fe76d91f33b2441de87597ae5885ea9005f35b1c Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Tue, 28 Nov 2023 20:06:41 +0100 Subject: refactor: seperate cli crate Signed-off-by: Henry Gressmann --- crates/cli/bin.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 crates/cli/bin.rs (limited to 'crates/cli/bin.rs') 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(()) +} -- cgit v1.3.1