From e81ad3c7eb5d6dee6acf6197bad3b495452ac9e2 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 8 Aug 2022 15:25:15 -0700 Subject: [PATCH] cli-flags: Don't ignore the first flag in `CommonOptions::parse_from_str` (#4642) --- crates/cli-flags/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index 49ad0ce06a..5f57363f15 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -229,7 +229,11 @@ pub struct CommonOptions { impl CommonOptions { pub fn parse_from_str(s: &str) -> Result { - let parts = s.split(" "); + let parts = s.split(" ").filter(|s| !s.is_empty()); + // The first argument is the name of the executable, which we don't use + // here, but have to provide because `clap` skips over it, and otherwise + // our first CLI flag will be ignored. + let parts = Some("wasmtime").into_iter().chain(parts); let options = Self::try_parse_from(parts).context("unable to parse options from passed flags")?; Ok(options) @@ -722,11 +726,11 @@ mod test { assert_eq!(use_func(""), use_clap_parser(&[])); assert_eq!( - use_func("foo --wasm-features=threads"), + use_func("--wasm-features=threads"), use_clap_parser(&["foo", "--wasm-features=threads"]) ); assert_eq!( - use_func("foo --cranelift-set enable_simd=true"), + use_func("--cranelift-set enable_simd=true"), use_clap_parser(&["foo", "--cranelift-set", "enable_simd=true"]) ); }