Skip to content

Commit 6613b6b

Browse files
committed
fix: correct file names in scaffold
1 parent afa3907 commit 6613b6b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/bin/scaffold.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ fn safe_create_file(path: &str) -> Result<File, std::io::Error> {
4343
OpenOptions::new().write(true).create_new(true).open(path)
4444
}
4545

46+
fn create_file(path: &str) -> Result<File, std::io::Error> {
47+
OpenOptions::new().write(true).create(true).open(path)
48+
}
49+
4650
fn main() {
4751
let day = match parse_args() {
4852
Ok(day) => day,
@@ -54,9 +58,9 @@ fn main() {
5458

5559
let day_padded = format!("{:02}", day);
5660

57-
let input_path = format!("src/inputs/{}.txt", day);
58-
let example_path = format!("src/examples/{}.txt", day);
59-
let module_path = format!("src/bin/{}.rs", day);
61+
let input_path = format!("src/inputs/{}.txt", day_padded);
62+
let example_path = format!("src/examples/{}.txt", day_padded);
63+
let module_path = format!("src/bin/{}.rs", day_padded);
6064

6165
let mut file = match safe_create_file(&module_path) {
6266
Ok(file) => file,
@@ -66,7 +70,7 @@ fn main() {
6670
}
6771
};
6872

69-
match file.write_all(MODULE_TEMPLATE.replace("DAY", &day_padded).as_bytes()) {
73+
match file.write_all(MODULE_TEMPLATE.replace("DAY", &day.to_string()).as_bytes()) {
7074
Ok(_) => {
7175
println!("Created module file \"{}\"", &module_path);
7276
}
@@ -76,7 +80,7 @@ fn main() {
7680
}
7781
}
7882

79-
match safe_create_file(&input_path) {
83+
match create_file(&input_path) {
8084
Ok(_) => {
8185
println!("Created empty input file \"{}\"", &input_path);
8286
}
@@ -86,7 +90,7 @@ fn main() {
8690
}
8791
}
8892

89-
match safe_create_file(&example_path) {
93+
match create_file(&example_path) {
9094
Ok(_) => {
9195
println!("Created empty example file \"{}\"", &example_path);
9296
}
@@ -97,5 +101,5 @@ fn main() {
97101
}
98102

99103
println!("---");
100-
println!("🎄 Type `cargo run --bin {}` to run your solution.", &day);
104+
println!("🎄 Type `cargo run --bin {}` to run your solution.", &day_padded);
101105
}

0 commit comments

Comments
 (0)