Skip to content

Commit 0bfa1b7

Browse files
committed
Add version requirement format option to cargo tree
Also update unit tests with test cases for normal and inverted output. Signed-off-by: Alexandre Barone <[email protected]>
1 parent 158d8e9 commit 0bfa1b7

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/cargo/ops/tree/format/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum Chunk {
1616
Repository,
1717
Features,
1818
LibName,
19+
VersionRequirement,
1920
}
2021

2122
pub struct Pattern(Vec<Chunk>);
@@ -32,6 +33,7 @@ impl Pattern {
3233
RawChunk::Argument("r") => Chunk::Repository,
3334
RawChunk::Argument("f") => Chunk::Features,
3435
RawChunk::Argument("lib") => Chunk::LibName,
36+
RawChunk::Argument("vr") => Chunk::VersionRequirement,
3537
RawChunk::Argument(a) => {
3638
bail!("unsupported pattern `{}`", a);
3739
}
@@ -65,6 +67,7 @@ impl<'a> fmt::Display for Display<'a> {
6567
Node::Package(NodePackage {
6668
package_id,
6769
features,
70+
version_req,
6871
..
6972
}) => {
7073
let package = self.graph.package_for_id(*package_id);
@@ -113,6 +116,9 @@ impl<'a> fmt::Display for Display<'a> {
113116
write!(fmt, "{}", target.crate_name())?;
114117
}
115118
}
119+
Chunk::VersionRequirement => {
120+
write!(fmt, "{}", version_req)?;
121+
}
116122
}
117123
}
118124
}

tests/testsuite/cargo_tree/deps.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,25 +1246,25 @@ foo v0.1.0 ([ROOT]/foo) [bar,default,dep_that_is_awesome,foo,other-dep]
12461246
.run();
12471247

12481248
p.cargo("tree --all-features")
1249-
.arg("--format={p}")
1249+
.arg("--format={p} satisfies {vr}")
12501250
.with_stdout_data(str![[r#"
1251-
foo v0.1.0 ([ROOT]/foo)
1252-
├── dep v1.0.0
1253-
├── dep_that_is_awesome v1.0.0
1254-
└── other-dep v1.0.0
1255-
└── dep v1.0.0
1251+
foo v0.1.0 ([ROOT]/foo) satisfies *
1252+
├── dep v1.0.0 satisfies =1.0
1253+
├── dep_that_is_awesome v1.0.0 satisfies >=1.0, <2
1254+
└── other-dep v1.0.0 satisfies ^1.0
1255+
└── dep v1.0.0 satisfies =1.0
12561256
12571257
"#]])
12581258
.run();
12591259

12601260
p.cargo("tree --all-features")
1261-
.arg("--format={p}")
1261+
.arg("--format={p} satisfies {vr}")
12621262
.arg("--invert=dep")
12631263
.with_stdout_data(str![[r#"
1264-
dep v1.0.0
1265-
├── foo v0.1.0 ([ROOT]/foo)
1266-
└── other-dep v1.0.0
1267-
└── foo v0.1.0 ([ROOT]/foo)
1264+
dep v1.0.0 satisfies =1.0
1265+
├── foo v0.1.0 ([ROOT]/foo) satisfies *
1266+
└── other-dep v1.0.0 satisfies ^1.0
1267+
└── foo v0.1.0 ([ROOT]/foo) satisfies *
12681268
12691269
"#]])
12701270
.run();

0 commit comments

Comments
 (0)