Skip to content

Commit

Permalink
Remove modified document file if directed
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfrishkorn committed Aug 20, 2023
1 parent a29db54 commit ea49098
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ fn main() -> Result<(), Box<dyn Error>> {
.help("edited document file")
.num_args(1)
.action(ArgAction::Append),
)
.arg(
Arg::new("remove")
.help("remove document file on successful update")
.short('r')
.num_args(0)
.action(ArgAction::SetTrue),
),
);

Expand Down Expand Up @@ -786,6 +793,14 @@ fn main() -> Result<(), Box<dyn Error>> {
// collect attachments before printing so they are included in output
s.collect_attachments(&conn)?;
s.print();

// remove modified document file if requested
if sub_matches.get_flag("remove") {
match std::fs::remove_file(file) {
Ok(_) => eprintln!("removed {}", file),
Err(e) => eprintln!("error removing file {}: {}", file, e),
}
}
} else {
eprintln!("update failed");
std::process::exit(1);
Expand Down

0 comments on commit ea49098

Please sign in to comment.