Skip to content

Commit

Permalink
add support for creating file if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
reykjalin committed Mar 25, 2024
1 parent 236af4b commit 504b16f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ impl TemplateApp {
let config = if let Some(file) = file {
// FIXME: Using .as_str() here to satisfy the borrow checker seems odd.
// I'm probably doing something wrong here.
let metadata = std::fs::metadata(file.as_str())
.unwrap_or_else(|_| panic!("File not found: {}", file.as_str()));
let metadata = std::fs::metadata(file.as_str()).unwrap_or_else(|_| {
std::fs::File::create(file.as_str())
.expect("Could not create file")
.metadata()
.expect("Could not get metadata for file")
});

if metadata.is_file() {
// FIXME: Inform user of file read error more gracefully than with a panic.
Expand Down

0 comments on commit 504b16f

Please sign in to comment.