1- use crate :: utils:: { bytes_to_best_size, pretty_dates, request, write_json_to_file } ;
1+ use crate :: utils:: { bytes_to_best_size, pretty_dates, request, write_to_file } ;
22use serde:: { Deserialize , Serialize } ;
33use serde_json:: Value ;
44use std:: path:: PathBuf ;
@@ -123,6 +123,7 @@ pub fn releases_command(
123123
124124 if all && !display {
125125 println ! ( "{}" , serde_json:: to_string_pretty( & json) . unwrap( ) ) ;
126+ write_json ( serde_json:: to_string_pretty ( & json) . unwrap ( ) , output) ;
126127 } else if all && display {
127128 let mut download_count = 0 ;
128129 for release in & simple_data {
@@ -133,9 +134,11 @@ pub fn releases_command(
133134 if link {
134135 println ! ( "Latest Release: {}" , simple_data[ 0 ] . html_url)
135136 }
137+ write_json ( serde_json:: to_string_pretty ( & simple_data) . unwrap ( ) , output) ;
136138 } else if !all && !display {
137139 if individual {
138140 println ! ( "{}" , serde_json:: to_string_pretty( & simple_data) . unwrap( ) ) ;
141+ write_json ( serde_json:: to_string_pretty ( & simple_data) . unwrap ( ) , output) ;
139142 } else {
140143 let mut overview = simple_data[ 0 ] . clone ( ) ;
141144 let mut download_count = 0 ;
@@ -146,6 +149,7 @@ pub fn releases_command(
146149 overview. downloads = download_count;
147150
148151 println ! ( "{}" , serde_json:: to_string_pretty( & overview) . unwrap( ) ) ;
152+ write_json ( serde_json:: to_string_pretty ( & overview) . unwrap ( ) , output) ;
149153 }
150154 } else if !all && display {
151155 let mut download_count = 0 ;
@@ -163,11 +167,14 @@ pub fn releases_command(
163167 if link {
164168 println ! ( "Latest Release: {}" , simple_data[ 0 ] . html_url)
165169 }
170+ write_json ( serde_json:: to_string_pretty ( & simple_data) . unwrap ( ) , output) ;
166171 }
172+ }
167173
174+ fn write_json ( json_string : String , output : Option < PathBuf > ) {
168175 match output {
169176 Some ( path) => {
170- let result = write_json_to_file ( json , path) ;
177+ let result = write_to_file ( serde_json :: to_string_pretty ( & json_string ) . unwrap ( ) , path) ;
171178 match result {
172179 Ok ( _) => { }
173180 Err ( err) => println ! ( "{}" , err) ,
0 commit comments