diff --git a/src/bin/cargo/commands/tree.rs b/src/bin/cargo/commands/tree.rs index f7af78263bd..6f064dfb80f 100644 --- a/src/bin/cargo/commands/tree.rs +++ b/src/bin/cargo/commands/tree.rs @@ -204,19 +204,18 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { } _ => { return Err(format_err!( - "The `-i` flag requires a package name.\n\ -\n\ -The `-i` flag is used to inspect the reverse dependencies of a specific\n\ -package. It will invert the tree and display the packages that depend on the\n\ -given package.\n\ -\n\ -Note that in a workspace, by default it will only display the package's\n\ -reverse dependencies inside the tree of the workspace member in the current\n\ -directory. The --workspace flag can be used to extend it so that it will show\n\ -the package's reverse dependencies across the entire workspace. The -p flag\n\ -can be used to display the package's reverse dependencies only with the\n\ -subtree of the package given to -p.\n\ -" + r#"a package name is required for `-i` but none was supplied + +note: `-p -i` is not supported; pass the package name to `-i` directly. + +help: to inspect the reverse dependencies of a specific package, pass the name directly to `-i`: + + cargo tree -i + +help: if you are in a workspace and want to search across all members, use: + + cargo tree --workspace -i +"# ) .into()); } diff --git a/tests/testsuite/cargo_tree/deps.rs b/tests/testsuite/cargo_tree/deps.rs index 5262469e1b3..97128555c96 100644 --- a/tests/testsuite/cargo_tree/deps.rs +++ b/tests/testsuite/cargo_tree/deps.rs @@ -751,6 +751,60 @@ c v1.0.0 │ └── foo v0.1.0 ([ROOT]/foo) └── foo v0.1.0 ([ROOT]/foo) +"#]]) + .run(); +} + +#[cargo_test] +fn invert_without_package_name() { + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/lib.rs", "") + .build(); + + p.cargo("tree -i") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] a package name is required for `-i` but none was supplied + +[NOTE] `-p -i` is not supported; pass the package name to `-i` directly. + +[HELP] to inspect the reverse dependencies of a specific package, pass the name directly to `-i`: + + cargo tree -i + +[HELP] if you are in a workspace and want to search across all members, use: + + cargo tree --workspace -i + + +"#]]) + .run(); +} + +#[cargo_test] +fn invert_without_package_name_workspace() { + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/lib.rs", "") + .build(); + + p.cargo("tree --workspace -i") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] a package name is required for `-i` but none was supplied + +[NOTE] `-p -i` is not supported; pass the package name to `-i` directly. + +[HELP] to inspect the reverse dependencies of a specific package, pass the name directly to `-i`: + + cargo tree -i + +[HELP] if you are in a workspace and want to search across all members, use: + + cargo tree --workspace -i + + "#]]) .run(); }