Skip to content

Commit

Permalink
Auto merge of #8115 - ehuss:tree-backwards-compat, r=alexcrichton
Browse files Browse the repository at this point in the history
Add backwards-compatibility for old cargo-tree flags.

Add backwards compatibility for the flags that were removed.

`--invert` is still not backwards compatible because it was fundamentally changed to take an argument.

Requested via #8062 (comment).
  • Loading branch information
bors committed Apr 15, 2020
2 parents f22d17c + b0fa64b commit 2cb9243
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/bin/cargo/commands/tree.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::cli;
use crate::command_prelude::*;
use anyhow::{bail, format_err};
use cargo::core::dependency::DepKind;
Expand Down Expand Up @@ -88,9 +89,22 @@ pub fn cli() -> App {
.short("f")
.default_value("{p}"),
)
.arg(
// Backwards compatibility with old cargo-tree.
Arg::with_name("version")
.long("version")
.short("V")
.hidden(true),
)
}

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
if args.is_present("version") {
let verbose = args.occurrences_of("verbose") > 0;
let version = cli::get_version_string(verbose);
print!("{}", version);
return Ok(());
}
let prefix = if args.is_present("no-indent") {
config
.shell()
Expand All @@ -106,12 +120,13 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
};
let prefix = tree::Prefix::from_str(prefix).map_err(|e| anyhow::anyhow!("{}", e))?;

let no_dedupe = args.is_present("no-dedupe") || args.is_present("all");
if args.is_present("all") {
return Err(format_err!(
"The `cargo tree` --all flag has been changed to --no-dedupe.\n\
If you are looking to display all workspace members, use the --workspace flag."
)
.into());
config.shell().warn(
"The `cargo tree` --all flag has been changed to --no-dedupe, \
and may be removed in a future version.\n\
If you are looking to display all workspace members, use the --workspace flag.",
)?;
}

let target = if args.is_present("all-targets") {
Expand Down Expand Up @@ -170,7 +185,7 @@ subtree of the package given to -p.\n\
edge_kinds,
invert,
prefix,
no_dedupe: args.is_present("no-dedupe"),
no_dedupe,
duplicates: args.is_present("duplicates"),
charset,
format: args.value_of("format").unwrap().to_string(),
Expand Down

0 comments on commit 2cb9243

Please sign in to comment.