|
10 | 10 | // THE SOFTWARE. |
11 | 11 | // |
12 | 12 |
|
| 13 | +using Microsoft.PowerShell.Commands; |
13 | 14 | using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic; |
14 | 15 | using System; |
15 | 16 | using System.Collections.Generic; |
16 | | -using System.ComponentModel.Composition; |
17 | 17 | using System.Diagnostics.CodeAnalysis; |
18 | 18 | using System.Globalization; |
19 | 19 | using System.Linq; |
20 | 20 | using System.Management.Automation; |
21 | | -using System.Resources; |
22 | | -using System.Threading; |
23 | | -using System.Reflection; |
24 | 21 |
|
25 | 22 | namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Commands |
26 | 23 | { |
@@ -56,6 +53,21 @@ public string[] Name |
56 | 53 | set { name = value; } |
57 | 54 | } |
58 | 55 | private string[] name; |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Severity: Array of the severity types to be enabled. |
| 59 | + /// </summary> |
| 60 | + /// </summary> |
| 61 | + [ValidateSet("Warning", "Error", "Information", IgnoreCase = true)] |
| 62 | + [Parameter(Mandatory = false)] |
| 63 | + [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] |
| 64 | + public string[] Severity |
| 65 | + { |
| 66 | + get { return severity; } |
| 67 | + set { severity = value; } |
| 68 | + } |
| 69 | + private string[] severity; |
| 70 | + |
59 | 71 | #endregion Parameters |
60 | 72 |
|
61 | 73 | #region Private Members |
@@ -128,9 +140,16 @@ protected override void ProcessRecord() |
128 | 140 | } |
129 | 141 | else |
130 | 142 | { |
| 143 | + if (severity != null) |
| 144 | + { |
| 145 | + var ruleSeverity = severity.Select(item => Enum.Parse(typeof (RuleSeverity), item)); |
| 146 | + rules = rules.Where(item => ruleSeverity.Contains(item.GetSeverity())).ToList(); |
| 147 | + } |
| 148 | + |
131 | 149 | foreach (IRule rule in rules) |
132 | 150 | { |
133 | | - WriteObject(new RuleInfo(rule.GetName(), rule.GetCommonName(), rule.GetDescription(), rule.GetSourceType(), rule.GetSourceName())); |
| 151 | + WriteObject(new RuleInfo(rule.GetName(), rule.GetCommonName(), rule.GetDescription(), |
| 152 | + rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity())); |
134 | 153 | } |
135 | 154 | } |
136 | 155 | } |
|
0 commit comments