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/Cargo.toml | 15 +++++++++++++++ crates/cli/bin.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 crates/cli/Cargo.toml create mode 100644 crates/cli/bin.rs (limited to 'crates/cli') diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml new file mode 100644 index 0000000..cdd0266 --- /dev/null +++ b/crates/cli/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name="tinywasm-cli" +version="0.0.0" +edition="2021" + +[[bin]] +name="tinywasm" +path="bin.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tinywasm={path="../core"} +argh="0.1" +color-eyre="0.6" 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