advent-of-code-rust
advent-of-code-rust copied to clipboard
feat(scaffold): overwrite argument
Solves #62
Hey @AV3RG, thanks for the PR. This looks like a good addition. Lmk once this is ready for review and I'll take a closer look.
Hey I just tested it and it works
The only change I could see that could be made is change the safe_create_file function to something like this
fn safe_create_file(path: &str, overwrite: bool) -> Result<File, std::io::Error> {
let mut open_options = OpenOptions::new().write(true);
if overwrite {
open_options = open_options.create(true).truncate(true);
} else {
open_options = open_options.create_new(true);
}
open_options.open(path)
}
Or by using a match statement, otherwise it works