@@ -130,44 +130,101 @@ public static Task<IBuildResult> BuildAsync(this ICommandLine commandLine, Actio
130
130
ArgumentNullException . ThrowIfNull ( commandLine ) ;
131
131
return Root . BuildRunner . RunAsync ( commandLine , handler , cancellationToken ) ;
132
132
}
133
-
134
- public static T EnsureSuccess < T > (
135
- this T result ,
136
- Func < T , bool ? > ? isSuccess = default ,
133
+
134
+ private static T EnsureSuccess < T , TResult > (
135
+ T result ,
136
+ Func < TResult , bool ? > ? isSuccess = default ,
137
137
int ? failureExitCode = 1 )
138
- where T : ICommandLineResult
138
+ where T : IEnumerable < TResult >
139
+ where TResult : ICommandLineResult
139
140
{
140
141
ArgumentNullException . ThrowIfNull ( result ) ;
141
142
isSuccess ??= r => r is ISuccessDeterminant successDeterminant ? successDeterminant . IsSuccess : true ;
142
- switch ( isSuccess ( result ) )
143
+ var hasError = false ;
144
+ foreach ( var nextResult in result )
143
145
{
144
- case true :
145
- return result ;
146
+ switch ( isSuccess ( nextResult ) )
147
+ {
148
+ case true :
149
+ break ;
146
150
147
- case null :
148
- Root . Log . Warning ( $ "{ result } .") ;
149
- return result ;
151
+ case null :
152
+ Root . Log . Warning ( $ "{ nextResult } .") ;
153
+ break ;
150
154
151
- case false :
152
- Root . Log . Error ( ErrorId . Build , $ "{ result } .") ;
153
- if ( failureExitCode is not { } exitCode )
154
- {
155
- return result ;
156
- }
157
-
158
- Root . ExitTracker . Exit ( exitCode ) ;
159
- return result ;
155
+ case false :
156
+ hasError = true ;
157
+ Root . Log . Error ( ErrorId . Build , $ "{ nextResult } .") ;
158
+ break ;
159
+ }
160
+ }
161
+
162
+ if ( hasError && failureExitCode is { } exitCode )
163
+ {
164
+ Root . ExitTracker . Exit ( exitCode ) ;
160
165
}
166
+
167
+ return result ;
168
+ }
169
+
170
+ public static IEnumerable < TResult > EnsureSuccess < TResult > (
171
+ this IEnumerable < TResult > results ,
172
+ Func < TResult , bool ? > ? isSuccess = default ,
173
+ int ? failureExitCode = 1 )
174
+ where TResult : ICommandLineResult
175
+ {
176
+ ArgumentNullException . ThrowIfNull ( results ) ;
177
+ return EnsureSuccess < IEnumerable < TResult > , TResult > ( results , isSuccess , failureExitCode ) ;
161
178
}
162
179
163
- public static async Task < T > EnsureSuccess < T > (
164
- this Task < T > resultTask ,
165
- Func < T , bool ? > ? isSuccess = default ,
180
+ public static async Task < IEnumerable < TResult > > EnsureSuccess < TResult > (
181
+ this Task < IEnumerable < TResult > > result ,
182
+ Func < TResult , bool ? > ? isSuccess = default ,
166
183
int ? failureExitCode = 1 )
167
- where T : ICommandLineResult
184
+ where TResult : ICommandLineResult
168
185
{
169
- ArgumentNullException . ThrowIfNull ( resultTask ) ;
170
- return EnsureSuccess ( await resultTask , isSuccess , failureExitCode ) ;
186
+ ArgumentNullException . ThrowIfNull ( result ) ;
187
+ return EnsureSuccess < IEnumerable < TResult > , TResult > ( await result , isSuccess , failureExitCode ) ;
188
+ }
189
+
190
+ public static TResult [ ] EnsureSuccess < TResult > (
191
+ this TResult [ ] results ,
192
+ Func < TResult , bool ? > ? isSuccess = default ,
193
+ int ? failureExitCode = 1 )
194
+ where TResult : ICommandLineResult
195
+ {
196
+ ArgumentNullException . ThrowIfNull ( results ) ;
197
+ return EnsureSuccess < TResult [ ] , TResult > ( results , isSuccess , failureExitCode ) ;
198
+ }
199
+
200
+ public static async Task < TResult [ ] > EnsureSuccess < TResult > (
201
+ this Task < TResult [ ] > result ,
202
+ Func < TResult , bool ? > ? isSuccess = default ,
203
+ int ? failureExitCode = 1 )
204
+ where TResult : ICommandLineResult
205
+ {
206
+ ArgumentNullException . ThrowIfNull ( result ) ;
207
+ return EnsureSuccess < TResult [ ] , TResult > ( await result , isSuccess , failureExitCode ) ;
208
+ }
209
+
210
+ public static TResult EnsureSuccess < TResult > (
211
+ this TResult result ,
212
+ Func < TResult , bool ? > ? isSuccess = default ,
213
+ int ? failureExitCode = 1 )
214
+ where TResult : ICommandLineResult
215
+ {
216
+ ArgumentNullException . ThrowIfNull ( result ) ;
217
+ return EnsureSuccess ( [ result ] , isSuccess , failureExitCode ) . First ( ) ;
218
+ }
219
+
220
+ public static async Task < TResult > EnsureSuccess < TResult > (
221
+ this Task < TResult > result ,
222
+ Func < TResult , bool ? > ? isSuccess = default ,
223
+ int ? failureExitCode = 1 )
224
+ where TResult : ICommandLineResult
225
+ {
226
+ ArgumentNullException . ThrowIfNull ( result ) ;
227
+ return EnsureSuccess ( await result , isSuccess , failureExitCode ) ;
171
228
}
172
229
173
230
public static bool TryGet < T > (
0 commit comments