From 411f3d60f38859716d820bee0a2180684ee7396a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 May 2022 15:30:41 -0500 Subject: [PATCH] Tweak CLI fallback to the `run` command (#4161) I ran across a case in Wasmtime today where a poor error message came out of the CLI. For example before this commit you would get: $ cargo run wast --wasm-features component-model foo.wast error: Invalid value "wast" for '': module name cannot be the same as a subcommand and now after this commit you get: $ cargo run wast --wasm-features component-model foo.wast error: Invalid value "component-model" for '--wasm-features ': unsupported WebAssembly feature 'component-model' I believe this was an accidental regression from #4082 since Wasmtime 0.36.0 produces the error message as expected. I opted to invert the conditional logic for falling back to the `run` subcommand. Instead of having a small set of error kinds that print the first-level error a small set of error kinds are now used to fall back to the `run` subcommand by default. My hope is that as `ErrorKind` is extended over time with various sorts of errors of parsing argumenst this'll be more robust because most of the time we want the CLI invocation to print out the normal CLI error, it's only in a select few cases that using `run` is likely to succeed. --- src/bin/wasmtime.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bin/wasmtime.rs b/src/bin/wasmtime.rs index c65245c749..f4b908ef0f 100644 --- a/src/bin/wasmtime.rs +++ b/src/bin/wasmtime.rs @@ -59,11 +59,10 @@ impl Wasmtime { fn main() -> Result<()> { Wasmtime::try_parse() .unwrap_or_else(|e| match e.kind() { - ErrorKind::DisplayHelp - | ErrorKind::DisplayVersion - | ErrorKind::MissingSubcommand - | ErrorKind::MissingRequiredArgument => e.exit(), - _ => Wasmtime::Run(RunCommand::parse()), + ErrorKind::UnrecognizedSubcommand | ErrorKind::UnknownArgument => { + Wasmtime::Run(RunCommand::parse()) + } + _ => e.exit(), }) .execute() }