Skip to content

Support a shorthand for specifying features when cargo adding multiple crates #10809

Open
@kotx

Description

@kotx

Problem

cargo add can be a bit annoying when specifying features for multiple crates. For example:
cargo add serde sqlx --features serde/derive sqlx/postgres fails with error: invalid character `/` in dependency name: `sqlx/postgres`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)

It's necessary to use one of

$ cargo add serde --features serde/derive sqlx --features sqlx/postgres
$ cargo add serde -F serde/derive sqlx -F sqlx/postgres
$ cargo add serde sqlx -F serde/derive,sqlx/postgres
$ cargo add serde sqlx -F "serde/derive sqlx/postgres"

But those methods are also cumbersome in having to specify the crate name multiple times

Proposed Solution

It would be useful to have a shorthand for specifying features, whether

  • Like pip extra's: cargo add serde[derive] sqlx[postgres,sqlite]
    • If we're daring maybe even cargo add sqlx[-default,postgres,sqlite]
  • Like cargo feature or the cargo-edit version of cargo add: cargo add serde +derive sqlx +postgres +sqlite
  • Allowing bare feature names when unambigious: cargo add serde -F derive sqlx -F postgres -F sqlite

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-addS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions