diff options
Diffstat (limited to 'crates/cli')
| -rw-r--r-- | crates/cli/Cargo.toml | 3 | ||||
| -rw-r--r-- | crates/cli/README.md | 2 | ||||
| -rw-r--r-- | crates/cli/src/args.rs | 9 | ||||
| -rw-r--r-- | crates/cli/src/bin.rs | 10 |
4 files changed, 15 insertions, 9 deletions
diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index caf541b..8472afb 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -1,7 +1,7 @@ [package] name="tinywasm-cli" version.workspace=true -description="TinyWasm CLI" +description="Command-line interface for TinyWasm" edition.workspace=true license.workspace=true authors.workspace=true @@ -9,6 +9,7 @@ repository.workspace=true rust-version.workspace=true keywords.workspace=true categories=["wasm"] +readme="README.md" [[bin]] name="tinywasm-cli" diff --git a/crates/cli/README.md b/crates/cli/README.md index 70b2cff..aa4d0c8 100644 --- a/crates/cli/README.md +++ b/crates/cli/README.md @@ -8,4 +8,6 @@ It is recommended to use the library directly instead of the CLI. ```bash $ cargo install tinywasm-cli $ tinywasm-cli --help +$ tinywasm-cli run ./module.wasm +$ tinywasm-cli run ./module.wasm -f add -a i32:1 -a i32:2 ``` 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(); |
