Skip to content

Commit de8338d

Browse files
author
Kapil Borle
committed
Read command data files from module settings folder
1 parent abd558d commit de8338d

1 file changed

Lines changed: 40 additions & 12 deletions

File tree

Rules/UseCompatibleCmdlets.cs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.IO;
1818
using System.Linq;
1919
using System.Management.Automation.Language;
20+
using System.Reflection;
2021
using System.Text.RegularExpressions;
2122
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
2223

@@ -100,21 +101,42 @@ private void SetupCmdletsDictionary()
100101
}
101102
}
102103

103-
var mode = GetStringArgFromListStringArg(ruleArgs["mode"]);
104-
switch (mode)
104+
object modeObject;
105+
if (ruleArgs.TryGetValue("mode", out modeObject))
105106
{
106-
case "online":
107-
ProcessOnlineModeArgs(ruleArgs);
108-
break;
107+
// This is for testing only. User should not be specifying mode!
108+
var mode = GetStringArgFromListStringArg(modeObject);
109+
switch (mode)
110+
{
111+
case "online":
112+
ProcessOnlineModeArgs(ruleArgs);
113+
break;
109114

110-
case "offline":
111-
ProcessOfflineModeArgs(ruleArgs);
112-
break;
115+
case "offline":
116+
ProcessOfflineModeArgs(ruleArgs);
117+
break;
113118

114-
case null:
115-
default:
116-
return;
119+
case null:
120+
default:
121+
break;
122+
}
123+
124+
return;
125+
}
126+
127+
// Find the compatibility files in Settings folder
128+
var path = this.GetType().GetTypeInfo().Assembly.Location;
129+
if (String.IsNullOrWhiteSpace(path))
130+
{
131+
return;
117132
}
133+
134+
var settingsPath = Path.Combine(Path.GetDirectoryName(path), "Settings");
135+
if (!Directory.Exists(settingsPath))
136+
{
137+
return;
138+
}
139+
ProcessDirectory(settingsPath);
118140
}
119141

120142
private bool GetVersionInfoFromPlatformString(
@@ -166,7 +188,13 @@ private void ProcessOfflineModeArgs(Dictionary<string, object> ruleArgs)
166188
// TODO: log this
167189
return;
168190
}
169-
foreach (var filePath in Directory.EnumerateFiles(uri))
191+
192+
ProcessDirectory(uri);
193+
}
194+
195+
private void ProcessDirectory(string path)
196+
{
197+
foreach (var filePath in Directory.EnumerateFiles(path))
170198
{
171199
var extension = Path.GetExtension(filePath);
172200
if (String.IsNullOrWhiteSpace(extension)

0 commit comments

Comments
 (0)