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

Handling of multiple features being passed to cargo-metadata #37

Closed
JaimeValdemoros opened this issue Feb 14, 2022 · 0 comments · Fixed by #38
Closed

Handling of multiple features being passed to cargo-metadata #37

JaimeValdemoros opened this issue Feb 14, 2022 · 0 comments · Fixed by #38
Labels
bug Something isn't working

Comments

@JaimeValdemoros
Copy link

JaimeValdemoros commented Feb 14, 2022

Describe the bug
Multiple features are passed to cargo-metadata as --features foo bar rather than --features foo,bar

To Reproduce

$ cargo new krates-test && cd krates-test
$ cargo add [email protected]
$ cat <<EOF >src/main.rs
use krates::{Builder, Cmd, Krates};
fn main() {
    let mut cmd = Cmd::new();
    cmd.manifest_path("./Cargo.toml");
    cmd.features(vec!["foo".to_string(), "bar".to_string()]);
    let _: Krates = Builder::new().build(cmd, |_| {}).unwrap();
}
EOF
$ cat <<EOF >>Cargo.toml

[features]
foo = []
bar = []
EOF
$ cargo --quiet run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Metadata(CargoMetadata { stderr: "error: Found argument 'foo' which wasn't expected, or isn't valid in this context\n\nUSAGE:\n    cargo metadata --features <FEATURES>... --format-version <VERSION> --manifest-path <PATH>\n\nFor more information try --help\n" })', src/main.rs:8:55
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Additional context
Replacing vec!["foo".to_string(), "bar".to_string()] with vec!["foo,bar".to_string()] causes it to run successfully.

I suspect this is due to the following lines - opts.append(&mut cmd.features); should instead be opts.push(cmd.features.join(","));:

krates/src/builder.rs

Lines 158 to 161 in ad78f9e

if !cmd.features.is_empty() {
opts.push("--features".to_owned());
opts.append(&mut cmd.features);
}
.

@JaimeValdemoros JaimeValdemoros added the bug Something isn't working label Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant