Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub struct Opts {
rustfmt_options: Vec<String>,

/// 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")]
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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);
}
Expand All @@ -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!(
Expand Down