Skip to content

"cargo add" should use dotted keys if already used in Cargo.toml #521

@jonasbb

Description

@jonasbb

Recently, the crate learned how to process Cargo.toml files with dotted keys (#400).
It would be great if cargo add could keep the formatting in the Cargo.toml consistent, meaning that if it uses dotted keys, new entries should follow the format and not use inline tables.

# Before
serde_json.version = "1.0.68"

# After: cargo add serde --features=derive
serde = { version = "1.0.130", features = ["derive"] }
serde_json.version = "1.0.68"

# How it should look like
serde.features = ["derive"]
serde.version = "1.0.130"
serde_json.version = "1.0.68"

"cargo add" already tries to keep entries sorted, if the Cargo.toml was sorted (#401). There is also an open issue about keeping the string style consistent (#217). Using the dotted keys syntax feels similar to those two issues.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions