@@ -34,6 +34,7 @@ public class InvokeScriptAnalyzerCommand : PSCmdlet, IOutputWriter
3434
3535 #region Private variables
3636 List < string > processedPaths ;
37+ private int totalDiagnosticCount = 0 ;
3738 #endregion // Private variables
3839
3940 #region Parameters
@@ -412,6 +413,10 @@ protected override void EndProcessing()
412413 {
413414 ScriptAnalyzer . Instance . CleanUp ( ) ;
414415 base . EndProcessing ( ) ;
416+
417+ if ( EnableExit ) {
418+ this . Host . SetShouldExit ( totalDiagnosticCount ) ;
419+ }
415420 }
416421
417422 protected override void StopProcessing ( )
@@ -426,10 +431,12 @@ protected override void StopProcessing()
426431
427432 private void ProcessInput ( )
428433 {
429- WriteToOutput ( RunAnalysis ( ) ) ;
434+ var diagnosticRecords = RunAnalysis ( ) ;
435+ WriteToOutput ( diagnosticRecords ) ;
436+ totalDiagnosticCount += diagnosticRecords . Count ;
430437 }
431438
432- private IEnumerable < DiagnosticRecord > RunAnalysis ( )
439+ private List < DiagnosticRecord > RunAnalysis ( )
433440 {
434441 if ( ! IsFileParameterSet ( ) )
435442 {
@@ -454,7 +461,7 @@ private IEnumerable<DiagnosticRecord> RunAnalysis()
454461 return diagnostics ;
455462 }
456463
457- private void WriteToOutput ( IEnumerable < DiagnosticRecord > diagnosticRecords )
464+ private void WriteToOutput ( List < DiagnosticRecord > diagnosticRecords )
458465 {
459466 foreach ( ILogger logger in ScriptAnalyzer . Instance . Loggers )
460467 {
@@ -507,11 +514,6 @@ private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
507514 }
508515 }
509516 }
510-
511- if ( EnableExit . IsPresent )
512- {
513- this . Host . SetShouldExit ( diagnosticRecords . Count ( ) ) ;
514- }
515517 }
516518
517519 private void ProcessPath ( )
@@ -535,4 +537,4 @@ private bool OverrideSwitchParam(bool paramValue, string paramName)
535537
536538 #endregion // Private Methods
537539 }
538- }
540+ }
0 commit comments