1616
1717import ArgumentParser
1818import ContainerAPIClient
19- import ContainerLog
2019import ContainerPersistence
21- import ContainerPlugin
2220import ContainerResource
2321import ContainerizationError
2422import Foundation
25- import Logging
26- import SwiftProtobuf
2723
2824extension Application {
2925 public struct ImageInspect : AsyncLoggableCommand {
@@ -39,19 +35,22 @@ extension Application {
3935
4036 public init ( ) { }
4137
42- struct InspectError : Error {
43- let succeeded : [ String ]
44- let failed : [ ( String , Error ) ]
45- }
46-
4738 public func run( ) async throws {
4839 let containerSystemConfig : ContainerSystemConfig = try await ConfigurationLoader . load ( )
49- var printable : [ ImageDetail ] = [ ]
50- var succeededImages : [ String ] = [ ]
51- var allErrors : [ ( String , Error ) ] = [ ]
40+ let uniqueNames = Set ( images)
41+ let result = try await ClientImage . get (
42+ names: Array ( uniqueNames) , containerSystemConfig: containerSystemConfig
43+ )
5244
53- let result = try await ClientImage . get ( names: images, containerSystemConfig: containerSystemConfig)
45+ if !result. error. isEmpty {
46+ let missing = result. error. sorted ( )
47+ throw ContainerizationError (
48+ . notFound,
49+ message: " image not found: \( missing. joined ( separator: " , " ) ) "
50+ )
51+ }
5452
53+ var printable : [ ImageDetail ] = [ ]
5554 for image in result. images {
5655 guard
5756 !Utility. isInfraImage (
@@ -61,29 +60,9 @@ extension Application {
6160 )
6261 else { continue }
6362 printable. append ( try await image. details ( ) )
64- succeededImages. append ( image. reference)
6563 }
6664
67- for missing in result. error {
68- allErrors. append ( ( missing, ContainerizationError ( . notFound, message: " Image not found " ) ) )
69- }
70-
71- if !printable. isEmpty {
72- try Output . emit ( Output . renderJSON ( printable) )
73- }
74-
75- if !allErrors. isEmpty {
76- for (name, error) in allErrors {
77- log. error (
78- " image inspect failed " ,
79- metadata: [
80- " name " : " \( name) " ,
81- " error " : " \( error. localizedDescription) " ,
82- ] )
83- }
84-
85- throw InspectError ( succeeded: succeededImages, failed: allErrors)
86- }
65+ try Output . emit ( Output . renderJSON ( printable) )
8766 }
8867 }
8968}
0 commit comments