Skip to content

Commit

Permalink
Merge pull request #4728 from wasmerio/fix-erroneous-subcommand-run
Browse files Browse the repository at this point in the history
feat(cli): Fix erroneous subcommand as a `run` tentative
  • Loading branch information
xdoardo authored May 21, 2024
2 parents 22c2415 + 4f30cc5 commit 3dee029
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod validate;
#[cfg(feature = "wast")]
mod wast;
mod whoami;
use std::env::args;

#[cfg(target_os = "linux")]
pub use binfmt::*;
Expand Down Expand Up @@ -189,11 +190,27 @@ impl WasmerCmd {
match WasmerCmd::try_parse() {
Ok(args) => args.execute(),
Err(e) => {
let first_arg_is_subcommand = if let Some(first_arg) = args().nth(1) {
let mut ret = false;
let cmd = WasmerCmd::command();

for cmd in cmd.get_subcommands() {
if cmd.get_name() == first_arg {
ret = true;
break;
}
}

ret
} else {
false
};

let might_be_wasmer_run = matches!(
e.kind(),
clap::error::ErrorKind::InvalidSubcommand
| clap::error::ErrorKind::UnknownArgument
);
) && !first_arg_is_subcommand;

if might_be_wasmer_run {
if let Ok(run) = Run::try_parse() {
Expand Down

0 comments on commit 3dee029

Please sign in to comment.