Add --backup flag
This commit is contained in:
parent
a8e7a7c8b8
commit
8396da1882
3 changed files with 7 additions and 2 deletions
|
|
@ -91,6 +91,7 @@ fn make_opts() -> Options {
|
||||||
let mut opts = Options::new();
|
let mut opts = Options::new();
|
||||||
|
|
||||||
// Sorted in alphabetical order.
|
// Sorted in alphabetical order.
|
||||||
|
opts.optflag("", "backup", "Backup any modified files.");
|
||||||
opts.optflag(
|
opts.optflag(
|
||||||
"",
|
"",
|
||||||
"check",
|
"check",
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,11 @@ impl CliOptions {
|
||||||
return Err(format_err!("Invalid to set write-mode and `--check`"));
|
return Err(format_err!("Invalid to set write-mode and `--check`"));
|
||||||
}
|
}
|
||||||
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
|
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
|
||||||
|
if write_mode == WriteMode::Overwrite && matches.opt_present("backup") {
|
||||||
|
options.write_mode = Some(WriteMode::Replace);
|
||||||
|
} else {
|
||||||
options.write_mode = Some(write_mode);
|
options.write_mode = Some(write_mode);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(format_err!(
|
return Err(format_err!(
|
||||||
"Invalid write-mode: {}, expected one of {}",
|
"Invalid write-mode: {}, expected one of {}",
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ pub use config::{file_lines, load_config, Config, Verbosity, WriteMode};
|
||||||
|
|
||||||
pub type FmtResult<T> = std::result::Result<T, failure::Error>;
|
pub type FmtResult<T> = std::result::Result<T, failure::Error>;
|
||||||
|
|
||||||
pub const WRITE_MODE_LIST: &str = "[replace|overwrite|display|plain|diff|coverage|checkstyle]";
|
pub const WRITE_MODE_LIST: &str = "[overwrite|display|plain|diff|coverage|checkstyle]";
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue