@@ -127,13 +127,6 @@ fn download_all_templates(
127127
128128 let section = format ! ( "# ===== {} =====\n {}\n \n " , remote_filename, content) ;
129129 file:: save_file ( & section, & dest_path, force) ?;
130-
131- println ! (
132- "{} Downloaded gitignore template: {} to {}" ,
133- "✓" . green( ) ,
134- remote_filename,
135- dest_path. display( )
136- ) ;
137130 }
138131 } else {
139132 // Merge all templates into a single .gitignore file
@@ -212,13 +205,6 @@ fn download_templates(
212205 } else {
213206 file:: save_file ( & section, & dest_path, force) ?;
214207 }
215-
216- println ! (
217- "{} Added gitignore template: {} to {}" ,
218- "✓" . green( ) ,
219- template_name,
220- dest_path. display( )
221- ) ;
222208 }
223209 } else if output. len ( ) == templates. len ( ) {
224210 // Save each template to its own file as specified in output
@@ -252,41 +238,57 @@ fn download_templates(
252238 ) ;
253239 }
254240 } else if output. len ( ) == 1 {
255- // Merge all templates into one file
241+ // Merge all templates into one file, but skip invalid templates and collect errors
256242 let mut merged_content = String :: new ( ) ;
243+ let mut errors = Vec :: new ( ) ;
257244
258245 for template_name in templates {
259- let template_path = find_template_in_cache ( template_name, cache) ?;
260- let url = format ! ( "{}/{}" , GITHUB_RAW_BASE , template_path) ;
261-
262- let msg = format ! ( "Downloading gitignore template: {}" , template_name) ;
263- let pb = progress:: spinner ( & msg) ;
264- let content = fetcher. fetch_content ( & url) ?;
265- pb. set_message ( "Download Complete" ) ;
266- pb. finish_and_clear ( ) ;
267-
268- merged_content. push_str ( & format ! (
269- "# ===== {}.gitignore =====\n {}\n \n " ,
270- template_name, content
271- ) ) ;
246+ match find_template_in_cache ( template_name, cache) {
247+ Ok ( template_path) => {
248+ let url = format ! ( "{}/{}" , GITHUB_RAW_BASE , template_path) ;
249+
250+ let msg = format ! ( "Downloading gitignore template: {}" , template_name) ;
251+ let pb = progress:: spinner ( & msg) ;
252+ match fetcher. fetch_content ( & url) {
253+ Ok ( content) => {
254+ pb. set_message ( "Download Complete" ) ;
255+ pb. finish_and_clear ( ) ;
256+ merged_content. push_str ( & format ! (
257+ "# ===== {}.gitignore =====\n {}\n \n " ,
258+ template_name, content
259+ ) ) ;
260+ }
261+ Err ( e) => {
262+ pb. finish_and_clear ( ) ;
263+ errors. push ( format ! (
264+ "Failed to fetch template '{}': {}" ,
265+ template_name, e
266+ ) ) ;
267+ }
268+ }
269+ }
270+ Err ( e) => {
271+ errors. push ( format ! ( "Template '{}' not found: {}" , template_name, e) ) ;
272+ }
273+ }
272274 }
273275
274276 let dest_path = dir_path
275277 . map ( |p| p. join ( & output[ 0 ] ) )
276278 . unwrap_or_else ( || Path :: new ( OUTPUT_BASE_PATH ) . join ( OUTPUT ) . join ( & output[ 0 ] ) ) ;
277279
278- if append {
279- file:: append_file ( & merged_content, & dest_path, None ) ?;
280- } else {
281- file:: save_file ( & merged_content, & dest_path, force) ?;
280+ if !merged_content. is_empty ( ) {
281+ if append {
282+ file:: append_file ( & merged_content, & dest_path, None ) ?;
283+ } else {
284+ file:: save_file ( & merged_content, & dest_path, force) ?;
285+ }
282286 }
283287
284- println ! (
285- "{} Added gitignore templates: {} to {}" ,
286- "✓" . green( ) ,
287- templates. join( ", " ) ,
288- dest_path. display( )
289- ) ;
288+ // Print errors for invalid templates
289+ for error in errors {
290+ eprintln ! ( "{}" , error. red( ) ) ;
291+ }
290292 } else {
291293 return Err ( anyhow:: anyhow!(
292294 "Number of output files must be either 1 or match the number of templates when not using --use-remote-name"
0 commit comments