advent-of-code-rust icon indicating copy to clipboard operation
advent-of-code-rust copied to clipboard

feat(scaffold): overwrite argument

Open AV3RG opened this issue 1 year ago • 2 comments

Solves #62

AV3RG avatar Feb 22 '24 12:02 AV3RG

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.

fspoettel avatar Apr 09 '24 15:04 fspoettel

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

AV3RG avatar Apr 12 '24 11:04 AV3RG