Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cjglo opened this issue Apr 25, 2024 · 1 comment
Open

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

cjglo opened this issue Apr 25, 2024 · 1 comment

Comments

@cjglo
Copy link

cjglo commented Apr 25, 2024

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
Copy link
Author

cjglo commented Apr 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant