1+ use crate :: formatter:: { error_without_trace, info, success} ;
12use bytes:: Bytes ;
2- use colored:: * ;
33use reqwest:: header:: { ACCEPT , USER_AGENT } ;
44use serde:: Deserialize ;
55use std:: fs;
66use std:: fs:: File ;
77use std:: path:: Path ;
88use zip:: ZipArchive ;
9- use crate :: formatter:: { error_without_trace, info, success} ;
109
1110#[ derive( Deserialize , Debug ) ]
1211struct Release {
@@ -28,9 +27,7 @@ pub async fn handle_download(tag: Option<String>, features: Option<Vec<String>>)
2827 // Download the definitions
2928 info ( "Starting download process..." . to_string ( ) ) ;
3029 let bytes = match download_definitions_as_bytes ( tag) . await {
31- Some ( bytes) => {
32- bytes
33- }
30+ Some ( bytes) => bytes,
3431 None => {
3532 error_without_trace ( String :: from ( "Download failed." ) ) ;
3633 return ;
@@ -49,7 +46,10 @@ pub async fn handle_download(tag: Option<String>, features: Option<Vec<String>>)
4946 }
5047
5148 let path = Path :: new ( out_folder_path) ;
52- success ( format ! ( "Download was successful. Definitions are now available: {}." , path. display( ) ) ) ;
49+ success ( format ! (
50+ "Download was successful. Definitions are now available: {}." ,
51+ path. display( )
52+ ) ) ;
5353}
5454
5555async fn download_definitions_as_bytes ( tag : Option < String > ) -> Option < bytes:: Bytes > {
@@ -100,11 +100,11 @@ async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Byt
100100 . into_iter ( )
101101 . find ( |a| a. name == "definitions.zip" )
102102 {
103- Some ( asset) => {
104- asset
105- }
103+ Some ( asset) => asset,
106104 None => {
107- panic ! ( "Definition folder is not called `definitions.zip` and was not inside the asset folder of the GitHub release!" ) ;
105+ panic ! (
106+ "Definition folder is not called `definitions.zip` and was not inside the asset folder of the GitHub release!"
107+ ) ;
108108 }
109109 } ;
110110
@@ -127,7 +127,10 @@ async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Byt
127127 }
128128 }
129129 } else {
130- error_without_trace ( format ! ( "Download failed with status: {}" , response. status( ) ) ) ;
130+ error_without_trace ( format ! (
131+ "Download failed with status: {}" ,
132+ response. status( )
133+ ) ) ;
131134 None
132135 }
133136 }
@@ -138,7 +141,6 @@ async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Byt
138141}
139142
140143async fn convert_bytes_to_folder ( bytes : Bytes , zip_path : & str ) {
141-
142144 if let Err ( e) = fs:: write ( zip_path, & bytes) {
143145 panic ! ( "Failed to write zip file: {e}" )
144146 }
@@ -151,9 +153,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
151153 } ;
152154
153155 let mut archive = match ZipArchive :: new ( zip_file) {
154- Ok ( archive) => {
155- archive
156- }
156+ Ok ( archive) => archive,
157157 Err ( e) => {
158158 panic ! ( "Failed to read zip archive: {e}" ) ;
159159 }
@@ -177,11 +177,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
177177
178178 if file. name ( ) . ends_with ( '/' ) {
179179 if let Err ( e) = fs:: create_dir_all ( & out_path) {
180- panic ! (
181- "Failed to create directory {}: {}" ,
182- out_path. display( ) ,
183- e
184- ) ;
180+ panic ! ( "Failed to create directory {}: {}" , out_path. display( ) , e) ;
185181 }
186182 } else {
187183 if let Some ( p) = out_path. parent ( ) {
@@ -203,11 +199,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
203199 }
204200 }
205201 Err ( e) => {
206- panic ! (
207- "Failed to create file {}: {}" ,
208- out_path. display( ) ,
209- e
210- ) ;
202+ panic ! ( "Failed to create file {}: {}" , out_path. display( ) , e) ;
211203 }
212204 }
213205 }
@@ -218,7 +210,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
218210
219211 match fs:: remove_file ( zip_path) {
220212 Ok ( _) => info ( "Temporary zip file removed" . to_string ( ) ) ,
221- Err ( e) => error_without_trace ( format ! ( "Warning: Failed to remove temporary zip file: {e}" ) )
213+ Err ( e) => error_without_trace ( format ! ( "Warning: Failed to remove temporary zip file: {e}" ) ) ,
222214 }
223215}
224216
@@ -227,12 +219,14 @@ async fn filter_features(selected_features: Vec<String>) {
227219
228220 match fs:: read_dir ( definitions_path) {
229221 Ok ( entries) => {
230-
231222 for entry in entries {
232223 let directory = match entry {
233224 Ok ( directory) => directory,
234225 Err ( e) => {
235- panic ! ( "{}" , format!( "Warning: Failed to read directory entry: {e}" ) ) ;
226+ panic ! (
227+ "{}" ,
228+ format!( "Warning: Failed to read directory entry: {e}" )
229+ ) ;
236230 }
237231 } ;
238232
@@ -249,9 +243,7 @@ async fn filter_features(selected_features: Vec<String>) {
249243 }
250244 }
251245 Err ( e) => {
252- error_without_trace (
253- format ! ( "Failed to read definitions directory: {e}" )
254- ) ;
246+ error_without_trace ( format ! ( "Failed to read definitions directory: {e}" ) ) ;
255247 }
256248 }
257249}
0 commit comments