rust-lang / cargo

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

Option for `cargo tree` to filter out (non-)workspace members #14420

Open zeichenreihe opened 2 months ago

zeichenreihe commented 2 months ago

Problem

I'm opening this issue because https://github.com/rust-lang/cargo/issues/8105#issuecomment-1284860085 said to open one if one wanted that feature.

cargo tree allows with --prune to remove dependencies from the list. However, as mentioned in https://github.com/rust-lang/cargo/issues/8105#issuecomment-846336129 it only takes in SPEC, and not the proposed "non-members" or "members".

This would be useful to have, since it would allow easily viewing the dependency tree with only workspace members.

Proposed Solution

The solution would be adding some argument, that would then take the values both, member, and non-member (as mentioned in https://github.com/rust-lang/cargo/issues/8105#issuecomment-846336129).

I have no proposed name yet for the argument.

Notes

At the time of writing, there does not exist any such command, see https://github.com/rust-lang/cargo/blob/ba8b39413c74d08494f94a7542fe79aa636e1661/src/doc/src/commands/cargo-tree.md for the cargo tree documentation at the time of writing.

epage commented 2 months ago

This would be useful to have, since it would allow easily viewing the dependency tree with only workspace members.

Could you go into more detail on the use case for this? In what scenarios are you wanting to view a tree of only workspace members?

zeichenreihe commented 2 months ago

Scenarios:

I think the latter justifies it even more.

Yes it's currently possible to even get the same result, but this requires listing all the dependencies of all crates with --prune, which is annoying and doesn't scale well.

ehuss commented 2 weeks ago

The cargo team discussed this issue and felt mildly in favor of supporting such an option. We would like to avoid proliferating too many flags in general. One option we discussed was reusing another flag of --depth workspace to show only to the depth of the workspace members. We felt it would be helpful for being able to see the connections within a large workspace without seeing all the external dependencies.