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>': 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 <FEATURE,FEATURE,...>': 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.
This commit is contained in:
Alex Crichton
2022-05-18 15:30:41 -05:00
committed by GitHub
parent 02d5edc591
commit 411f3d60f3

View File

@@ -59,11 +59,10 @@ impl Wasmtime {
fn main() -> Result<()> { fn main() -> Result<()> {
Wasmtime::try_parse() Wasmtime::try_parse()
.unwrap_or_else(|e| match e.kind() { .unwrap_or_else(|e| match e.kind() {
ErrorKind::DisplayHelp ErrorKind::UnrecognizedSubcommand | ErrorKind::UnknownArgument => {
| ErrorKind::DisplayVersion Wasmtime::Run(RunCommand::parse())
| ErrorKind::MissingSubcommand }
| ErrorKind::MissingRequiredArgument => e.exit(), _ => e.exit(),
_ => Wasmtime::Run(RunCommand::parse()),
}) })
.execute() .execute()
} }