Skip to content

Commit 45e7f93

Browse files
author
Kapil Borle
committed
Make InvokeSA command to use common settings logic
1 parent d11b626 commit 45e7f93

1 file changed

Lines changed: 18 additions & 55 deletions

File tree

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030

3131
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
3232
{
33+
using PSSASettings = Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings;
34+
3335
/// <summary>
3436
/// InvokeScriptAnalyzerCommand: Cmdlet to statically check PowerShell scripts.
3537
/// </summary>
3638
[Cmdlet(VerbsLifecycle.Invoke,
3739
"ScriptAnalyzer",
38-
DefaultParameterSetName="File",
40+
DefaultParameterSetName = "File",
3941
HelpUri = "http://go.microsoft.com/fwlink/?LinkId=525914")]
4042
public class InvokeScriptAnalyzerCommand : PSCmdlet, IOutputWriter
4143
{
@@ -208,6 +210,9 @@ public SwitchParameter SaveDscDependency
208210
#endif // !PSV3
209211

210212
#if DEBUG
213+
/// <summary>
214+
/// Attaches to an instance of a .Net debugger
215+
/// </summary>
211216
[Parameter(Mandatory = false)]
212217
public SwitchParameter AttachAndDebug
213218
{
@@ -260,64 +265,22 @@ protected override void BeginProcessing()
260265
ProcessPath();
261266
}
262267

263-
object settingsFound;
264-
var settingsMode = PowerShell.ScriptAnalyzer.Settings.FindSettingsMode(
265-
this.settings,
266-
processedPaths == null || processedPaths.Count == 0 ? null : processedPaths[0],
267-
out settingsFound);
268-
269-
switch (settingsMode)
270-
{
271-
case SettingsMode.Auto:
272-
this.WriteVerbose(
273-
String.Format(
274-
CultureInfo.CurrentCulture,
275-
Strings.SettingsNotProvided,
276-
path));
277-
this.WriteVerbose(
278-
String.Format(
279-
CultureInfo.CurrentCulture,
280-
Strings.SettingsAutoDiscovered,
281-
(string)settingsFound));
282-
break;
283-
284-
case SettingsMode.Preset:
285-
case SettingsMode.File:
286-
this.WriteVerbose(
287-
String.Format(
288-
CultureInfo.CurrentCulture,
289-
Strings.SettingsUsingFile,
290-
(string)settingsFound));
291-
break;
292-
293-
case SettingsMode.Hashtable:
294-
this.WriteVerbose(
295-
String.Format(
296-
CultureInfo.CurrentCulture,
297-
Strings.SettingsUsingHashtable));
298-
break;
299-
300-
default: // case SettingsMode.None
301-
this.WriteVerbose(
302-
String.Format(
303-
CultureInfo.CurrentCulture,
304-
Strings.SettingsCannotFindFile));
305-
break;
306-
}
307-
308-
if (settingsMode != SettingsMode.None)
268+
try
309269
{
310-
try
270+
var settingsObj = PSSASettings.Create(
271+
settings,
272+
processedPaths == null || processedPaths.Count == 0 ? null : processedPaths[0],
273+
this);
274+
if (settingsObj != null)
311275
{
312-
var settingsObj = new Settings(settingsFound);
313276
ScriptAnalyzer.Instance.UpdateSettings(settingsObj);
314277
}
315-
catch
316-
{
317-
this.WriteWarning(String.Format(CultureInfo.CurrentCulture, Strings.SettingsNotParsable));
318-
stopProcessing = true;
319-
return;
320-
}
278+
}
279+
catch
280+
{
281+
this.WriteWarning(String.Format(CultureInfo.CurrentCulture, Strings.SettingsNotParsable));
282+
stopProcessing = true;
283+
return;
321284
}
322285

323286
ScriptAnalyzer.Instance.Initialize(

0 commit comments

Comments
 (0)