cargo-tree icon indicating copy to clipboard operation
cargo-tree copied to clipboard

Add depth option

Open mwilliammyers opened this issue 5 years ago • 4 comments

Adds the -D <DEPTH>/--depth <DEPTH> option.

Closes #60

Example:

❯ cargo tree -D 1

cargo-tree v0.27.0 (~/Developer/cargo-tree)
├── cargo v0.39.0
├── env_logger v0.7.0
├── failure v0.1.5
├── petgraph v0.4.13
└── structopt v0.3.2

Things to consider:

  • This PR is technically a breaking change because now dependencies are truncated if they are farther down the dependency tree instead of if they were already printed, i.e. deciding if we should truncate a dependency is breadth first. Technically the dependencies are still actually printed depth first but I thought it was pretty weird to have deps printing out that were deeper than the specified limit, only to have a * printed later on. This might lead to confusing behavior when used with the --duplicate option though?
  • Right now this treats packages specified by --package as the "root" package, i.e. instead of erroring:
     cargo tree -D1 -p syn:0.15.44
    rror: package syn v0.15.44 not found
    
    because syn is a transitive dependency with a depth >1, it prints out the dependencies of syn that have a depth <=1 from syn (not the real package root):
    yn v0.15.44
    ── proc-macro2 v0.4.30
    ── quote v0.6.13
    ── unicode-xid v0.1.0
    
    Is this the desired behavior?
  • Should we print out a * when truncating a dependency whose children are not being printed because they are above the --depth limit and is also a duplicate?

mwilliammyers avatar Sep 29 '19 03:09 mwilliammyers

Thanks, I'm looking forward to this! :)

Boscop avatar Oct 01 '19 06:10 Boscop

Thanks for working on this @mwilliammyers! What does it do if you set the --depth=1, and your dependency tree looks like this?

 A
 |- B
    |- C

However, A, B, and C are all in your workspace.

I think the ideal solution to #60 would let you show only dependencies referenced directly in your Cargo.toml files (ie. the things you've specified, local or remote).

therealbnut avatar Dec 13 '19 07:12 therealbnut

Assuming A is your "main" (or lib) crate then it would do:

 A
 |- B

mwilliammyers avatar Dec 13 '19 20:12 mwilliammyers

@sfackler if I fix the conflicts with master, is this a feature that you would consider adding?

mwilliammyers avatar May 18 '20 19:05 mwilliammyers