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

cargo add bar --features x, y, z is completely broken #14333

Closed
elfeiin opened this issue Aug 1, 2024 · 4 comments
Closed

cargo add bar --features x, y, z is completely broken #14333

elfeiin opened this issue Aug 1, 2024 · 4 comments
Labels
C-bug Category: bug

Comments

@elfeiin
Copy link

elfeiin commented Aug 1, 2024

Problem

The documentation says:

--features features
Space or comma separated list of [features to activate](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features). When adding multiple crates, the features for a specific crate may be enabled with package-name/feature-name syntax. This flag may be specified multiple times, which enables all specified features.

but doing the obvious cargo add bar --features x, y, z results in:

error: feature `x` must be qualified by the dependency it's being activated for, like `bar/x`, `y,/x`, `z/x`

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

@elfeiin elfeiin added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 1, 2024
@weihanglo
Copy link
Member

weihanglo commented Aug 1, 2024

For cargo add bar --features x, y, z specifically, you need to quote the feature list when providing value to --features flag if you want to activate x, y, and z features. Like

cargo add bar --features "x, y, z"

Because they are not quoted, y, and z turn into trailing positional arguments, which becomes crate names as if you ran cargo add "y," "z". Therefore, this behavior is expected.

Also the doc of the --features flag explicitly tells that if mutiple crates are provided, the value to the --features flag must in the form of <crate>/<feature> to disambiguate.

Given there is no version info and reproducible step in the issue description, and with my naive guess the behavior is expected, so going to close this. If you are ready to share a minimal reproduction with Rust version info, feel free to comment or reopen.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2024
@weihanglo weihanglo removed the S-triage Status: This issue is waiting on initial triage. label Aug 1, 2024
@elfeiin
Copy link
Author

elfeiin commented Aug 6, 2024

Examples could be added to the docs or the help info in the binary itself.

@weihanglo
Copy link
Member

Examples could be added to the docs or the help info in the binary itself.

Feel free to do so.

To me, I may add some examples like cargo add tokio -F fs,rt,net. I would avoid quoting in examples as they might not cross-platform. (It's hard to say if the above example is cross-platform. CLI is hard)

@epage
Copy link
Contributor

epage commented Aug 6, 2024

In general, I recommend avoiding spaces and would prefer for examples to not use them. Comma separated cases "just work" and they don't seem like they really need their own examples.

Maybe what we should do is adjust the help text to emphasize "comma" over "space".

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

No branches or pull requests

3 participants