From 25fef037adbf841b5f208983594bedac066b935d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 25 Feb 2021 18:39:02 +0300 Subject: [PATCH] Port cargo's new flag name See https://github.com/rust-lang/cargo/pull/7241 --- src/cargo-fmt/main.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index ec50bcdbcf7..090a7f71764 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -56,8 +56,8 @@ pub struct Opts { rustfmt_options: Vec, /// Format all packages, and also their local path-based dependencies - #[structopt(long = "all")] - format_all: bool, + #[structopt(long = "workspace", alias = "all")] + format_workspace: bool, /// Run rustfmt in check mode #[structopt(long = "check")] @@ -351,7 +351,7 @@ pub enum CargoFmtStrategy { impl CargoFmtStrategy { pub fn from_opts(opts: &Opts) -> CargoFmtStrategy { - match (opts.format_all, opts.packages.is_empty()) { + match (opts.format_workspace, opts.packages.is_empty()) { (false, true) => CargoFmtStrategy::Root, (true, _) => CargoFmtStrategy::All, (false, false) => CargoFmtStrategy::Some(opts.packages.clone()), @@ -698,7 +698,7 @@ mod cargo_fmt_tests { assert_eq!(false, o.check); assert_eq!(empty, o.packages); assert_eq!(empty, o.rustfmt_options); - assert_eq!(false, o.format_all); + assert_eq!(false, o.format_workspace); assert_eq!(None, o.manifest_path); assert_eq!(None, o.message_format); } @@ -725,10 +725,16 @@ mod cargo_fmt_tests { assert_eq!(true, o.check); assert_eq!(vec!["p1", "p2"], o.packages); assert_eq!(vec!["--edition", "2018"], o.rustfmt_options); - assert_eq!(false, o.format_all); + assert_eq!(false, o.format_workspace); assert_eq!(Some(String::from("short")), o.message_format); } + #[test] + fn workspace_alias() { + let o = Opts::from_iter(&["test", "--all"]); + assert_eq!(true, o.format_workspace); + } + #[test] fn unexpected_option() { assert!(