Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Fix erroneous subcommand as a run tentative #4728

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading