@@ -35,6 +35,7 @@ members = [\"adder\"]";
3535 let filename = path. join ( "Cargo.toml" ) ;
3636 let mut file = File :: create ( filename) ?;
3737 file. write_all ( content) ?;
38+
3839 Ok ( ( ) )
3940}
4041
@@ -43,14 +44,15 @@ fn write_toml(path: &Path, slug: &String, libraries: String) -> std::io::Result<
4344 let content = "[package]
4445name = \" package_name\"
4546version = \" 0.1.0\"
46- edition = \" 2024\"
47+ edition = \" 2024\" \n
4748[dependencies]\n "
4849 . replace ( "package_name" , slug. as_str ( ) ) ;
4950
5051 let filename = path. join ( "Cargo.toml" ) ;
5152 let mut file = File :: create ( filename) ?;
5253 file. write_all ( content. as_bytes ( ) ) ?;
5354 file. write_all ( libraries. as_bytes ( ) ) ?;
55+
5456 Ok ( ( ) )
5557}
5658
@@ -71,19 +73,33 @@ fn write_exercise(path: &Path, template: String) -> std::io::Result<()> {
7173
7274 let mut file = File :: create ( filename) ?;
7375 file. write_all ( template. as_bytes ( ) ) ?;
76+
7477 Ok ( ( ) )
7578}
7679
7780fn write_markdown (
7881 path : & Path ,
79- slug : & String ,
82+ name : String ,
8083 description : String ,
84+ level : String ,
8185 author : String ,
8286) -> std:: io:: Result < ( ) > {
83- dbg ! ( & path) ;
84- dbg ! ( & slug) ;
85- dbg ! ( & description) ;
86- dbg ! ( & author) ;
87+ // exercise markdown template
88+ let content = "# package_name
89+
90+ Level: package_level
91+ Author: package_author\n
92+ Instructions:
93+ package_description\n "
94+ . replace ( "package_name" , name. as_str ( ) )
95+ . replace ( "package_description" , description. as_str ( ) )
96+ . replace ( "package_level" , level. as_str ( ) )
97+ . replace ( "package_author" , author. as_str ( ) ) ;
98+
99+ let filename = path. join ( "README.md" ) ;
100+ let mut file = File :: create ( filename) ?;
101+ file. write_all ( content. as_bytes ( ) ) ?;
102+
87103 Ok ( ( ) )
88104}
89105
@@ -127,13 +143,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
127143 // re-write/update the toml and md files but make a backup copy of the
128144 // exercise file if it exists, in case it was already solved
129145 write_toml ( & exercise_path, & slug, bite. libraries ) ?;
130- write_markdown ( & exercise_path, & slug, bite. description , bite. author ) ?;
146+ write_markdown (
147+ & exercise_path,
148+ bite. name ,
149+ bite. description ,
150+ bite. level ,
151+ bite. author ,
152+ ) ?;
131153 write_exercise ( & exercise_path, bite. template ) ?;
132154 println ! ( " ✅" ) ;
133155 }
134156
135157 write_root_toml ( & base_path) ?;
136158
137- // all done
138159 Ok ( ( ) )
139160}
0 commit comments