diff options
Diffstat (limited to 'crates/cli')
| -rw-r--r-- | crates/cli/Cargo.toml | 4 | ||||
| -rw-r--r-- | crates/cli/bin.rs | 37 | ||||
| -rw-r--r-- | crates/cli/util.rs | 13 |
3 files changed, 19 insertions, 35 deletions
diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index bfe0391..783ead2 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -13,5 +13,5 @@ path="bin.rs" tinywasm={path="../tinywasm"} argh="0.1" color-eyre="0.6" -tracing="0.1" -tracing-subscriber="0.3" +log="0.4" +pretty_env_logger="0.5" diff --git a/crates/cli/bin.rs b/crates/cli/bin.rs index 2c554cd..9c6908d 100644 --- a/crates/cli/bin.rs +++ b/crates/cli/bin.rs @@ -2,9 +2,7 @@ use std::str::FromStr; use argh::FromArgs; use color_eyre::eyre::Result; -use tinywasm::{self, WasmValue}; -use util::install_tracing; - +use tinywasm::{self}; mod util; #[derive(FromArgs)] @@ -12,6 +10,10 @@ mod util; struct TinyWasmCli { #[argh(subcommand)] nested: TinyWasmSubcommand, + + /// log level + #[argh(option, short = 'l', default = "\"info\".to_string()")] + log_level: String, } #[derive(FromArgs)] @@ -22,7 +24,6 @@ enum TinyWasmSubcommand { enum Engine { Main, - Naive, } impl FromStr for Engine { @@ -30,7 +31,6 @@ impl FromStr for Engine { fn from_str(s: &str) -> Result<Self, Self::Err> { match s { - "naive" => Ok(Self::Naive), "main" => Ok(Self::Main), _ => Err(format!("unknown engine: {}", s)), } @@ -52,16 +52,26 @@ struct Run { fn main() -> Result<()> { color_eyre::install()?; - install_tracing(None); let args: TinyWasmCli = argh::from_env(); + let level = match args.log_level.as_str() { + "trace" => log::LevelFilter::Trace, + "debug" => log::LevelFilter::Debug, + "warn" => log::LevelFilter::Warn, + "error" => log::LevelFilter::Error, + "info" => log::LevelFilter::Info, + _ => log::LevelFilter::Info, + }; + + pretty_env_logger::formatted_builder() + .filter_level(level) + .init(); match args.nested { TinyWasmSubcommand::Run(Run { wasm_file, engine }) => { let wasm = std::fs::read(wasm_file)?; match engine { Engine::Main => run(&wasm), - Engine::Naive => run_naive(&wasm), } } } @@ -78,16 +88,3 @@ fn run(wasm: &[u8]) -> Result<()> { Ok(()) } - -fn run_naive(wasm: &[u8]) -> Result<()> { - let mut module = tinywasm::naive::Module::new(wasm)?; - let args = [WasmValue::I32(1), WasmValue::I32(2)]; - let res = tinywasm::naive::run(&mut module, "add", &args)?; - println!("res: {:?}", res); - - let args = [WasmValue::I64(1), WasmValue::I64(2)]; - let res = tinywasm::naive::run(&mut module, "add_64", &args)?; - println!("res: {:?}", res); - - Ok(()) -} diff --git a/crates/cli/util.rs b/crates/cli/util.rs index 2a8160a..8b13789 100644 --- a/crates/cli/util.rs +++ b/crates/cli/util.rs @@ -1,14 +1 @@ -pub fn install_tracing(log_level: Option<tracing::Level>) { - use tracing_subscriber::filter::LevelFilter; - use tracing_subscriber::prelude::*; - tracing_subscriber::registry() - .with( - tracing_subscriber::fmt::layer() - .compact() - .with_filter(LevelFilter::from( - log_level.unwrap_or(tracing::Level::DEBUG), - )), - ) - .init(); -} |
