summaryrefslogtreecommitdiff
path: root/crates/cli
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2023-11-28 20:06:41 +0100
committerHenry Gressmann <mail@henrygressmann.de>2023-11-28 20:06:41 +0100
commitfe76d91f33b2441de87597ae5885ea9005f35b1c (patch)
treebda08242444d91dbf55e5e96233ae826c5e4e376 /crates/cli
parent1256c4248d2a3a9f73c2a14d997a337ba0eee2b4 (diff)
refactor: seperate cli crate
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/cli')
-rw-r--r--crates/cli/Cargo.toml15
-rw-r--r--crates/cli/bin.rs43
2 files changed, 58 insertions, 0 deletions
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(())
+}