11use std:: { collections:: BTreeMap , io:: IsTerminal } ;
22
33use secrecy:: { ExposeSecret , SecretString } ;
4- use snafu:: { ResultExt , Snafu , ensure } ;
4+ use snafu:: { ResultExt , Snafu } ;
55
66use crate :: {
77 cli:: { ImageCheckArguments , ImageListArguments , Pretty } ,
@@ -14,33 +14,22 @@ use crate::{
1414#[ derive( Debug , Snafu ) ]
1515pub enum Error {
1616 #[ snafu( display( "failed to serialize list as JSON" ) ) ]
17- SerializeList {
18- source : serde_json:: Error ,
19- } ,
17+ SerializeList { source : serde_json:: Error } ,
2018
2119 #[ snafu( display( "failed to build list of targets" ) ) ]
22- BuildTargets {
23- source : bakefile:: TargetsError ,
24- } ,
20+ BuildTargets { source : bakefile:: TargetsError } ,
2521
2622 #[ snafu( display( "failed to build request client" ) ) ]
27- BuildClient {
28- source : reqwest:: Error ,
29- } ,
23+ BuildClient { source : reqwest:: Error } ,
3024
3125 #[ snafu( display( "failed to send request" ) ) ]
32- SendRequest {
33- source : reqwest:: Error ,
34- } ,
26+ SendRequest { source : reqwest:: Error } ,
3527
3628 #[ snafu( display( "failed to deserialize response" ) ) ]
37- DeserializeResponse {
38- source : reqwest:: Error ,
39- } ,
29+ DeserializeResponse { source : reqwest:: Error } ,
4030
41- MissingVersion {
42- image_name : String ,
43- } ,
31+ #[ snafu( display( "missing images found: \n {missing_images}" , missing_images = missing_images. join( "\n " ) ) ) ]
32+ MissingVersion { missing_images : Vec < String > } ,
4433}
4534
4635/// This is the `boil show images` command handler function.
@@ -100,6 +89,8 @@ pub async fn check_images(arguments: ImageCheckArguments, config: Config) -> Res
10089 . build ( )
10190 . context ( BuildClientSnafu ) ?;
10291
92+ let mut missing_images = Vec :: new ( ) ;
93+
10394 for ( image_name, ( image_config, _) ) in targets {
10495 for ( registry, registry_options) in image_config. metadata . registries {
10596 // Add tokens to a map so that we don't need construct the key and retrieve the value
@@ -110,7 +101,7 @@ pub async fn check_images(arguments: ImageCheckArguments, config: Config) -> Res
110101 } ) ;
111102
112103 println ! (
113- "Checking for {registry}/{registry_namespace}/{image_name}" ,
104+ "Checking {registry}/{registry_namespace}/{image_name}" ,
114105 registry_namespace = registry_options. namespace,
115106 ) ;
116107
@@ -133,22 +124,27 @@ pub async fn check_images(arguments: ImageCheckArguments, config: Config) -> Res
133124 . await
134125 . context ( DeserializeResponseSnafu ) ?;
135126
136- ensure ! (
137- image_config. versions. iter( ) . all( |( image_version, _) | {
138- let index_manifest_tag = format_image_index_manifest_tag(
139- image_version,
140- & config. metadata. vendor_tag_prefix,
141- & arguments. image_version,
142- ) ;
143-
144- println!( "- {image_name}:{index_manifest_tag}" ) ;
145- tag_list. tags. contains( & index_manifest_tag)
146- } ) ,
147- MissingVersionSnafu { image_name }
148- ) ;
127+ for ( image_version, _) in image_config. versions . iter ( ) {
128+ let index_manifest_tag = format_image_index_manifest_tag (
129+ image_version,
130+ & config. metadata . vendor_tag_prefix ,
131+ & arguments. image_version ,
132+ ) ;
133+
134+ let image_identifier = format ! ( "{image_name}:{index_manifest_tag}" ) ;
135+
136+ println ! ( "- {image_identifier}" ) ;
137+ if !tag_list. tags . contains ( & index_manifest_tag) {
138+ missing_images. push ( image_identifier) ;
139+ }
140+ }
149141 }
150142 }
151143
144+ if !missing_images. is_empty ( ) {
145+ return MissingVersionSnafu { missing_images } . fail ( ) ;
146+ }
147+
152148 Ok ( ( ) )
153149}
154150
0 commit comments