@@ -8,7 +8,7 @@ use serde::Serialize;
88use snafu:: { ResultExt , Snafu } ;
99
1010use crate :: {
11- cli:: { ImageCheckArguments , ImageListArguments , ImageSizeArguments , Pretty } ,
11+ cli:: { Format , ImageCheckArguments , ImageListArguments , ImageSizeArguments , Pretty } ,
1212 config:: Config ,
1313 core:: bakefile:: { self , Targets , TargetsOptions } ,
1414 models:: { Manifest , TagList } ,
@@ -70,7 +70,7 @@ pub fn list_images(arguments: ImageListArguments) -> Result<(), Error> {
7070 } )
7171 . collect ( ) ;
7272
73- print_to_stdout ( list, arguments. pretty )
73+ serialize_to_stdout ( list, arguments. pretty )
7474}
7575
7676pub async fn check_images ( arguments : ImageCheckArguments , config : Config ) -> Result < ( ) , Error > {
@@ -243,10 +243,35 @@ pub async fn calculate_size(arguments: ImageSizeArguments, config: Config) -> Re
243243 }
244244 }
245245
246- print_to_stdout ( result, Pretty :: Always )
246+ match arguments. format {
247+ Format :: Plain => {
248+ if let Some ( max_width) = result
249+ . images
250+ . iter ( )
251+ . map ( |i| i. 0 . len ( ) )
252+ . max_by ( |lhs, rhs| lhs. cmp ( rhs) )
253+ {
254+ for ( image, size) in result. images {
255+ println ! (
256+ "{image:max_width$} {size}" ,
257+ size = humansize:: format_size( size, humansize:: BINARY )
258+ ) ;
259+ }
260+
261+ println ! (
262+ "{total_text:max_width$} {total}" ,
263+ total_text = "Total" ,
264+ total = humansize:: format_size( result. total, humansize:: BINARY )
265+ )
266+ }
267+
268+ Ok ( ( ) )
269+ }
270+ Format :: Json => serialize_to_stdout ( & result, arguments. pretty ) ,
271+ }
247272}
248273
249- fn print_to_stdout < T > ( value : T , pretty : Pretty ) -> Result < ( ) , Error >
274+ fn serialize_to_stdout < T > ( value : T , pretty : Pretty ) -> Result < ( ) , Error >
250275where
251276 T : Serialize ,
252277{
0 commit comments