cli-flags: Don't ignore the first flag in CommonOptions::parse_from_str (#4642)
This commit is contained in:
@@ -229,7 +229,11 @@ pub struct CommonOptions {
|
||||
|
||||
impl CommonOptions {
|
||||
pub fn parse_from_str(s: &str) -> Result<Self> {
|
||||
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"])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user