rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.86k stars 2.43k forks source link

Sort the members lists of the workspace even if they were previously unordered #14809

Open linyihai opened 2 weeks ago

linyihai commented 2 weeks ago

Problem

If the list of working interval members is long and unordered, and then append the members via the 'cargo new' command, only manual sorting of the member list can be done.

The current design of cargo is that if the members list is in order, then the 'cargo new' command will sort the members list, thus ensuring that the members list is in order. The current design should be to scramble the contents of the members list, if it was previously out of order. But as I explained earlier, if the user wants to have an ordered list of members, then the user will have to work it out on their own

Proposed Solution

The one I can think of so far is the 'cargo new' subcommand that lets the user choose whether to sort the members list by adding an option.

Notes

No response

linyihai commented 2 weeks ago

The current design of cargo is that if the members list is in order, then the 'cargo new' command will sort the members list, thus ensuring that the members list is in order.

This is the corresponding code

https://github.com/rust-lang/cargo/blob/31c96be2c1259827507c1121f8c6e066eb5e58b3/src/cargo/ops/cargo_new.rs#L997-L1001

I had a big list of members, so i need to hack these code to sort the members.

epage commented 2 weeks ago

When we added cargo add to Cargo, we removed a --sort flag, instead saying formatting control is outside of the scope of that command and should instead live in a dedicated formatter. There is an issue for adding formatting to cargo fmt and I think that should instead be the focusd

linyihai commented 2 weeks ago

There is an issue for adding formatting to cargo fmt and I think that should instead be the focusd

Yes, after the sorting is done, it actually needs additional formatting.

epage commented 2 weeks ago

Sorting is part of formatting, like formatting of uses in Rust.