@@ -21,16 +21,14 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
21
21
/// </summary>
22
22
[ Cmdlet ( VerbsLifecycle . Invoke ,
23
23
"ScriptAnalyzer" ,
24
- DefaultParameterSetName = ParameterSet_Path_SuppressedOnly ,
24
+ DefaultParameterSetName = ParameterSet_Path ,
25
25
SupportsShouldProcess = true ,
26
26
HelpUri = "https://go.microsoft.com/fwlink/?LinkId=525914" ) ]
27
27
[ OutputType ( typeof ( DiagnosticRecord ) , typeof ( SuppressedRecord ) ) ]
28
28
public class InvokeScriptAnalyzerCommand : PSCmdlet , IOutputWriter
29
29
{
30
- private const string ParameterSet_Path_SuppressedOnly = nameof ( Path ) + "_" + nameof ( SuppressedOnly ) ;
31
- private const string ParameterSet_Path_IncludeSuppressed = nameof ( Path ) + "_" + nameof ( IncludeSuppressed ) ;
32
- private const string ParameterSet_ScriptDefinition_SuppressedOnly = nameof ( ScriptDefinition ) + "_" + nameof ( SuppressedOnly ) ;
33
- private const string ParameterSet_ScriptDefinition_IncludeSuppressed = nameof ( ScriptDefinition ) + "_" + nameof ( IncludeSuppressed ) ;
30
+ private const string ParameterSet_Path = "File" ;
31
+ private const string ParameterSet_ScriptDefinition = nameof ( ScriptDefinition ) ;
34
32
35
33
#region Private variables
36
34
List < string > processedPaths ;
@@ -41,12 +39,7 @@ public class InvokeScriptAnalyzerCommand : PSCmdlet, IOutputWriter
41
39
/// Path: The path to the file or folder to invoke PSScriptAnalyzer on.
42
40
/// </summary>
43
41
[ Parameter ( Position = 0 ,
44
- ParameterSetName = ParameterSet_Path_IncludeSuppressed ,
45
- Mandatory = true ,
46
- ValueFromPipeline = true ,
47
- ValueFromPipelineByPropertyName = true ) ]
48
- [ Parameter ( Position = 0 ,
49
- ParameterSetName = ParameterSet_Path_SuppressedOnly ,
42
+ ParameterSetName = ParameterSet_Path ,
50
43
Mandatory = true ,
51
44
ValueFromPipeline = true ,
52
45
ValueFromPipelineByPropertyName = true ) ]
@@ -63,12 +56,7 @@ public string Path
63
56
/// ScriptDefinition: a script definition in the form of a string to run rules on.
64
57
/// </summary>
65
58
[ Parameter ( Position = 0 ,
66
- ParameterSetName = ParameterSet_ScriptDefinition_IncludeSuppressed ,
67
- Mandatory = true ,
68
- ValueFromPipeline = true ,
69
- ValueFromPipelineByPropertyName = true ) ]
70
- [ Parameter ( Position = 0 ,
71
- ParameterSetName = ParameterSet_ScriptDefinition_SuppressedOnly ,
59
+ ParameterSetName = ParameterSet_ScriptDefinition ,
72
60
Mandatory = true ,
73
61
ValueFromPipeline = true ,
74
62
ValueFromPipelineByPropertyName = true ) ]
@@ -155,10 +143,8 @@ public string[] Severity
155
143
}
156
144
private string [ ] severity ;
157
145
158
- // TODO: This should be only in the Path parameter sets, and is ignored otherwise,
159
- // but we already have a test that depends on it being otherwise
160
- //[Parameter(ParameterSetName = ParameterSet_Path_IncludeSuppressed)]
161
- //[Parameter(ParameterSetName = ParameterSet_Path_SuppressedOnly)]
146
+ // TODO: This should be only in the Path parameter set, and is ignored otherwise,
147
+ // but we already have a test that depends on it being available with ScriptDefinition
162
148
//
163
149
/// <summary>
164
150
/// Recurse: Apply to all files within subfolders under the path
@@ -174,22 +160,19 @@ public SwitchParameter Recurse
174
160
/// <summary>
175
161
/// ShowSuppressed: Show the suppressed message
176
162
/// </summary>
177
- [ Parameter ( ParameterSetName = ParameterSet_Path_SuppressedOnly ) ]
178
- [ Parameter ( ParameterSetName = ParameterSet_ScriptDefinition_SuppressedOnly ) ]
163
+ [ Parameter ]
179
164
public SwitchParameter SuppressedOnly { get ; set ; }
180
165
181
166
/// <summary>
182
167
/// Include suppressed diagnostics in the output.
183
168
/// </summary>
184
- [ Parameter ( ParameterSetName = ParameterSet_Path_IncludeSuppressed , Mandatory = true ) ]
185
- [ Parameter ( ParameterSetName = ParameterSet_ScriptDefinition_IncludeSuppressed , Mandatory = true ) ]
169
+ [ Parameter ]
186
170
public SwitchParameter IncludeSuppressed { get ; set ; }
187
171
188
172
/// <summary>
189
173
/// Resolves rule violations automatically where possible.
190
174
/// </summary>
191
- [ Parameter ( Mandatory = false , ParameterSetName = ParameterSet_Path_IncludeSuppressed ) ]
192
- [ Parameter ( Mandatory = false , ParameterSetName = ParameterSet_Path_SuppressedOnly ) ]
175
+ [ Parameter ( ParameterSetName = ParameterSet_Path ) ]
193
176
public SwitchParameter Fix
194
177
{
195
178
get { return fix ; }
@@ -284,6 +267,18 @@ protected override void BeginProcessing()
284
267
}
285
268
}
286
269
#endif
270
+
271
+ if ( IncludeSuppressed && SuppressedOnly )
272
+ {
273
+ ThrowTerminatingError (
274
+ new ErrorRecord (
275
+ new InvalidOperationException ( $ "The { nameof ( IncludeSuppressed ) } and { nameof ( SuppressedOnly ) } parameters are mutually exclusive") ,
276
+ "SuppressionSwitchParametersInvalid" ,
277
+ ErrorCategory . InvalidArgument ,
278
+ targetObject : null ) ) ;
279
+ return ;
280
+ }
281
+
287
282
Helper . Instance = new Helper (
288
283
SessionState . InvokeCommand ,
289
284
this ) ;
0 commit comments