@@ -24,7 +24,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
2424 /// GetScriptAnalyzerRuleCommand: Cmdlet to list all the analyzer rule names and descriptions.
2525 /// </summary>
2626 [ Cmdlet ( VerbsCommon . Get , "ScriptAnalyzerRule" , HelpUri = "http://go.microsoft.com/fwlink/?LinkId=525913" ) ]
27- public class GetScriptAnalyzerRuleCommand : PSCmdlet
27+ public class GetScriptAnalyzerRuleCommand : PSCmdlet , IOutputWriter
2828 {
2929 #region Parameters
3030 /// <summary>
@@ -69,68 +69,22 @@ public string[] Severity
6969
7070 #endregion Parameters
7171
72- #region Private Members
73-
74- Dictionary < string , List < string > > validationResults = new Dictionary < string , List < string > > ( ) ;
75-
76- #endregion
77-
7872 #region Overrides
7973
8074 /// <summary>
8175 /// BeginProcessing : TBD
8276 /// </summary>
8377 protected override void BeginProcessing ( )
8478 {
85- #region Set PSCmdlet property of Helper
86-
87- Helper . Instance . MyCmdlet = this ;
88-
89- #endregion
90- // Verifies rule extensions
91- if ( customizedRulePath != null )
92- {
93- validationResults = ScriptAnalyzer . Instance . CheckRuleExtension ( customizedRulePath , this ) ;
94- foreach ( string extension in validationResults [ "InvalidPaths" ] )
95- {
96- WriteWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . MissingRuleExtension , extension ) ) ;
97- }
98- }
99- else
100- {
101- validationResults . Add ( "InvalidPaths" , new List < string > ( ) ) ;
102- validationResults . Add ( "ValidModPaths" , new List < string > ( ) ) ;
103- validationResults . Add ( "ValidDllPaths" , new List < string > ( ) ) ;
104- }
105-
106- try
107- {
108- if ( validationResults [ "ValidDllPaths" ] . Count == 0 )
109- {
110- ScriptAnalyzer . Instance . Initialize ( ) ;
111- }
112- else
113- {
114- ScriptAnalyzer . Instance . Initilaize ( validationResults ) ;
115- }
116- }
117- catch ( Exception ex )
118- {
119- ThrowTerminatingError ( new ErrorRecord ( ex , ex . HResult . ToString ( "X" , CultureInfo . CurrentCulture ) ,
120- ErrorCategory . NotSpecified , this ) ) ;
121- }
79+ ScriptAnalyzer . Instance . Initialize ( this , customizedRulePath ) ;
12280 }
12381
12482 /// <summary>
12583 /// ProcessRecord : TBD
12684 /// </summary>
12785 protected override void ProcessRecord ( )
12886 {
129- string [ ] modNames = null ;
130- if ( validationResults [ "ValidModPaths" ] . Count > 0 )
131- {
132- modNames = validationResults [ "ValidModPaths" ] . ToArray < string > ( ) ;
133- }
87+ string [ ] modNames = ScriptAnalyzer . Instance . GetValidModulePaths ( ) ;
13488
13589 IEnumerable < IRule > rules = ScriptAnalyzer . Instance . GetRule ( modNames , name ) ;
13690 if ( rules == null )
0 commit comments