Skip to content

Commit 8396da1

Browse files
committed
Add --backup flag
1 parent a8e7a7c commit 8396da1

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/bin/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ fn make_opts() -> Options {
9191
let mut opts = Options::new();
9292

9393
// Sorted in alphabetical order.
94+
opts.optflag("", "backup", "Backup any modified files.");
9495
opts.optflag(
9596
"",
9697
"check",

src/config/options.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ impl CliOptions {
368368
return Err(format_err!("Invalid to set write-mode and `--check`"));
369369
}
370370
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
371-
options.write_mode = Some(write_mode);
371+
if write_mode == WriteMode::Overwrite && matches.opt_present("backup") {
372+
options.write_mode = Some(WriteMode::Replace);
373+
} else {
374+
options.write_mode = Some(write_mode);
375+
}
372376
} else {
373377
return Err(format_err!(
374378
"Invalid write-mode: {}, expected one of {}",

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use config::{file_lines, load_config, Config, Verbosity, WriteMode};
6868

6969
pub type FmtResult<T> = std::result::Result<T, failure::Error>;
7070

71-
pub const WRITE_MODE_LIST: &str = "[replace|overwrite|display|plain|diff|coverage|checkstyle]";
71+
pub const WRITE_MODE_LIST: &str = "[overwrite|display|plain|diff|coverage|checkstyle]";
7272

7373
#[macro_use]
7474
mod utils;

0 commit comments

Comments
 (0)