mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
feat(tree): Add '--depth public' feature-gated value
This commit is contained in:
parent
038bd06a84
commit
224222ee34
@ -91,6 +91,7 @@ impl FromStr for Prefix {
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DisplayDepth {
|
||||
MaxDisplayDepth(u32),
|
||||
Public,
|
||||
Workspace,
|
||||
}
|
||||
|
||||
@ -100,6 +101,7 @@ impl FromStr for DisplayDepth {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"workspace" => Ok(Self::Workspace),
|
||||
"public" => Ok(Self::Public),
|
||||
s => s.parse().map(Self::MaxDisplayDepth).map_err(|_| {
|
||||
clap::Error::raw(
|
||||
clap::error::ErrorKind::ValueValidation,
|
||||
@ -420,6 +422,12 @@ fn print_dependencies<'a>(
|
||||
let (max_display_depth, filter_non_workspace_member) = match display_depth {
|
||||
DisplayDepth::MaxDisplayDepth(max) => (max, false),
|
||||
DisplayDepth::Workspace => (u32::MAX, true),
|
||||
DisplayDepth::Public => {
|
||||
if !ws.gctx().cli_unstable().unstable_options {
|
||||
anyhow::bail!("`--depth public` requires `-Zunstable-options`")
|
||||
}
|
||||
(u32::MAX, false)
|
||||
}
|
||||
};
|
||||
|
||||
// Current level exceeds maximum display depth. Skip.
|
||||
|
@ -1963,26 +1963,18 @@ fn depth_public() {
|
||||
.file("dep/src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("tree")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
.with_stdout_data(str![[r#"
|
||||
dep v0.1.0 ([ROOT]/foo/dep)
|
||||
|
||||
diamond v0.1.0 ([ROOT]/foo/diamond)
|
||||
├── left-pub v0.1.0 ([ROOT]/foo/left-pub)
|
||||
│ └── dep v0.1.0 ([ROOT]/foo/dep)
|
||||
└── right-priv v0.1.0 ([ROOT]/foo/right-priv)
|
||||
└── dep v0.1.0 ([ROOT]/foo/dep)
|
||||
|
||||
left-pub v0.1.0 ([ROOT]/foo/left-pub) (*)
|
||||
|
||||
right-priv v0.1.0 ([ROOT]/foo/right-priv) (*)
|
||||
p.cargo("tree --depth public")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] `--depth public` requires `-Zunstable-options`
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree -p left-pub")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree --depth public -p left-pub")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
left-pub v0.1.0 ([ROOT]/foo/left-pub)
|
||||
└── dep v0.1.0 ([ROOT]/foo/dep)
|
||||
@ -1990,8 +1982,9 @@ left-pub v0.1.0 ([ROOT]/foo/left-pub)
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree -p right-priv")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree --depth public -p right-priv")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
right-priv v0.1.0 ([ROOT]/foo/right-priv)
|
||||
└── dep v0.1.0 ([ROOT]/foo/dep)
|
||||
@ -1999,8 +1992,9 @@ right-priv v0.1.0 ([ROOT]/foo/right-priv)
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree -p diamond")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree --depth public -p diamond")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
diamond v0.1.0 ([ROOT]/foo/diamond)
|
||||
├── left-pub v0.1.0 ([ROOT]/foo/left-pub)
|
||||
@ -2011,8 +2005,9 @@ diamond v0.1.0 ([ROOT]/foo/diamond)
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree --depth public")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
dep v0.1.0 ([ROOT]/foo/dep)
|
||||
|
||||
@ -2029,8 +2024,9 @@ right-priv v0.1.0 ([ROOT]/foo/right-priv) (*)
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree --invert dep")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree --depth public --invert dep")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
dep v0.1.0 ([ROOT]/foo/dep)
|
||||
├── left-pub v0.1.0 ([ROOT]/foo/left-pub)
|
||||
|
@ -374,8 +374,9 @@ fn depth_public_no_features() {
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("tree -e features")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree -e features --depth public")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
foo v0.1.0 ([ROOT]/foo)
|
||||
├── priv-defaultdep feature "default"
|
||||
@ -424,8 +425,9 @@ fn depth_public_transitive_features() {
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("tree -e features")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree -e features --depth public")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
foo v0.1.0 ([ROOT]/foo)
|
||||
├── priv-defaultdep feature "default"
|
||||
@ -483,16 +485,18 @@ fn depth_public_cli() {
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("tree -e features")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree -e features --depth public")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
foo v0.1.0 ([ROOT]/foo)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree -e features --features pub-indirect")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree -e features --depth public --features pub-indirect")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
foo v0.1.0 ([ROOT]/foo)
|
||||
└── pub feature "default"
|
||||
@ -501,8 +505,9 @@ foo v0.1.0 ([ROOT]/foo)
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
p.cargo("tree -e features --features priv-indirect")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
p.cargo("tree -e features --depth public --features priv-indirect")
|
||||
.arg("-Zunstable-options")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency", "depth-public"])
|
||||
.with_stdout_data(str![[r#"
|
||||
foo v0.1.0 ([ROOT]/foo)
|
||||
└── priv feature "default"
|
||||
|
Loading…
x
Reference in New Issue
Block a user