summaryrefslogtreecommitdiff
path: root/crates/cli/bin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/cli/bin.rs')
-rw-r--r--crates/cli/bin.rs43
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(())
+}