Remove unnecessary manual CLI parsing

This commit is contained in:
Felix Schütt
2023-01-02 11:08:38 +01:00
parent 015fc8c349
commit b2d4e975e3

View File

@@ -229,24 +229,16 @@ fn wasmer_main_inner() -> Result<(), anyhow::Error> {
_ => {} _ => {}
} }
let command = args.get(1);
let options = if cfg!(target_os = "linux") && binpath.ends_with("wasmer-binfmt-interpreter") { let options = if cfg!(target_os = "linux") && binpath.ends_with("wasmer-binfmt-interpreter") {
WasmerCLIOptions::Run(Run::from_binfmt_args()) WasmerCLIOptions::Run(Run::from_binfmt_args())
} else { } else {
match command.unwrap_or(&"".to_string()).as_ref() { match WasmerCLIOptions::try_parse_from(args.iter()) {
"add" | "cache" | "compile" | "config" | "create-obj" | "create-exe" | "help" Ok(o) => o,
| "inspect" | "init" | "run" | "self-update" | "validate" | "wast" | "binfmt" Err(e) => {
| "list" | "login" | "publish" => WasmerCLIOptions::parse(), match e.kind() {
_ => { ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(),
WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| { _ => WasmerCLIOptions::Run(Run::parse()),
match e.kind() { }
// This fixes a issue that:
// 1. Shows the version twice when doing `wasmer -V`
// 2. Shows the run help (instead of normal help) when doing `wasmer --help`
ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(),
_ => WasmerCLIOptions::Run(Run::parse()),
}
})
} }
} }
}; };