diff options
Diffstat (limited to 'crates/cli/src')
| -rw-r--r-- | crates/cli/src/args.rs | 9 | ||||
| -rw-r--r-- | crates/cli/src/bin.rs | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 1fec2d5..0333c92 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -17,8 +17,11 @@ impl From<WasmArg> for WasmValue { impl FromStr for WasmArg { type Err = String; fn from_str(s: &str) -> std::prelude::v1::Result<Self, Self::Err> { - let [ty, val]: [&str; 2] = - s.split(':').collect::<Vec<_>>().try_into().map_err(|e| format!("invalid arguments: {e:?}"))?; + let [ty, val]: [&str; 2] = s + .split(':') + .collect::<Vec<_>>() + .try_into() + .map_err(|_e| "invalid argument format; expected type:value".to_string())?; let arg: WasmValue = match ty { "i32" => val.parse::<i32>().map_err(|e| format!("invalid argument value for i32: {e:?}"))?.into(), @@ -26,7 +29,7 @@ impl FromStr for WasmArg { "f32" => val.parse::<f32>().map_err(|e| format!("invalid argument value for f32: {e:?}"))?.into(), "f64" => val.parse::<f64>().map_err(|e| format!("invalid argument value for f64: {e:?}"))?.into(), "v128" => val.parse::<i128>().map_err(|e| format!("invalid argument value for v128: {e:?}"))?.into(), - t => return Err(format!("Invalid arg type: {t}")), + t => return Err(format!("invalid arg type `{t}`; expected one of i32, i64, f32, f64, v128")), }; Ok(WasmArg(arg)) diff --git a/crates/cli/src/bin.rs b/crates/cli/src/bin.rs index 9b283c3..7e32fed 100644 --- a/crates/cli/src/bin.rs +++ b/crates/cli/src/bin.rs @@ -19,7 +19,7 @@ struct TinyWasmCli { #[argh(subcommand)] nested: TinyWasmSubcommand, - /// log level + /// log level: trace, debug, info, warn, or error #[argh(option, short = 'l', default = "\"info\".to_string()")] log_level: String, } @@ -53,15 +53,15 @@ struct Run { #[argh(positional)] wasm_file: String, - /// function to run + /// exported function to run; omit to only instantiate and run start #[argh(option, short = 'f')] func: Option<String>, - /// arguments to pass to the wasm file + /// arguments passed to the function in type:value form #[argh(option, short = 'a')] args: Vec<WasmArg>, - /// engine to use + /// engine to use (currently only `main`) #[argh(option, short = 'e', default = "Engine::Main")] engine: Engine, } @@ -74,7 +74,7 @@ fn main() -> Result<()> { "warn" => log::LevelFilter::Warn, "error" => log::LevelFilter::Error, "info" => log::LevelFilter::Info, - _ => log::LevelFilter::Info, + other => return Err(eyre::eyre!("invalid log level `{other}`; expected trace, debug, info, warn, or error")), }; pretty_env_logger::formatted_builder().filter_level(level).init(); |
