Browse Source

cli-flags: Don't ignore the first flag in `CommonOptions::parse_from_str` (#4642)

pull/4652/head
Nick Fitzgerald 2 years ago
committed by GitHub
parent
commit
e81ad3c7eb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      crates/cli-flags/src/lib.rs

10
crates/cli-flags/src/lib.rs

@ -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"])
);
}

Loading…
Cancel
Save