@@ -43,6 +43,10 @@ fn safe_create_file(path: &str) -> Result<File, std::io::Error> {
43
43
OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( path)
44
44
}
45
45
46
+ fn create_file ( path : & str ) -> Result < File , std:: io:: Error > {
47
+ OpenOptions :: new ( ) . write ( true ) . create ( true ) . open ( path)
48
+ }
49
+
46
50
fn main ( ) {
47
51
let day = match parse_args ( ) {
48
52
Ok ( day) => day,
@@ -54,9 +58,9 @@ fn main() {
54
58
55
59
let day_padded = format ! ( "{:02}" , day) ;
56
60
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 ) ;
60
64
61
65
let mut file = match safe_create_file ( & module_path) {
62
66
Ok ( file) => file,
@@ -66,7 +70,7 @@ fn main() {
66
70
}
67
71
} ;
68
72
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 ( ) ) {
70
74
Ok ( _) => {
71
75
println ! ( "Created module file \" {}\" " , & module_path) ;
72
76
}
@@ -76,7 +80,7 @@ fn main() {
76
80
}
77
81
}
78
82
79
- match safe_create_file ( & input_path) {
83
+ match create_file ( & input_path) {
80
84
Ok ( _) => {
81
85
println ! ( "Created empty input file \" {}\" " , & input_path) ;
82
86
}
@@ -86,7 +90,7 @@ fn main() {
86
90
}
87
91
}
88
92
89
- match safe_create_file ( & example_path) {
93
+ match create_file ( & example_path) {
90
94
Ok ( _) => {
91
95
println ! ( "Created empty example file \" {}\" " , & example_path) ;
92
96
}
@@ -97,5 +101,5 @@ fn main() {
97
101
}
98
102
99
103
println ! ( "---" ) ;
100
- println ! ( "🎄 Type `cargo run --bin {}` to run your solution." , & day ) ;
104
+ println ! ( "🎄 Type `cargo run --bin {}` to run your solution." , & day_padded ) ;
101
105
}
0 commit comments