matklad / xshell

Apache License 2.0
696 stars 30 forks source link

Bug: Multiple blank flags seem to cause errors with cmd! #86

Open cjglo opened 6 months ago

cjglo commented 6 months ago

This could will result in an error:

use xshell::cmd;
fn main() {
    let x = (false).then_some("-s").unwrap_or_default();
    let y = (false).then_some("-b").unwrap_or_default();
    let sh = xshell::Shell::new().unwrap();
    cmd!(sh, "git status {x} {y}").run().unwrap();
}

Error

$ git status  
fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths
thread 'main' panicked at src/main.rs:7:42:
called `Result::unwrap()` on an `Err` value: command exited with non-zero code `git status  `: 128

Despite the fact git status is a valid command, as is git status -s -b

But this will not:

use xshell::cmd;
fn main() {
    let x = (false).then_some("-s").unwrap_or_default();
    let y = (false).then_some("-b").unwrap_or_default();
    let sh = xshell::Shell::new().unwrap();
    cmd!(sh, "git status").run().unwrap();
}

Ran into this bug when working on Bevy Game Engine, where the same thing caused issues with a cargo test. Except the error was:

command exited with non-zero code `cargo test --workspace --lib --bins --tests --benches  `: 1
error: unexpected argument '' found
cjglo commented 6 months ago

I may have time to look into this and submit a PR