@@ -131,11 +131,31 @@ private void SetupCmdletsDictionary()
131
131
return ;
132
132
}
133
133
134
+ var settingsPath = GetSettingsDirectory ( ) ;
135
+ if ( settingsPath == null )
136
+ {
137
+ return ;
138
+ }
139
+
140
+ ProcessDirectory ( settingsPath ) ;
141
+ }
142
+
143
+ private void ResetCurCmdletCompatibilityMap ( )
144
+ {
145
+ // cannot iterate over collection and change the values, hence the conversion to list
146
+ foreach ( var key in curCmdletCompatibilityMap . Keys . ToList ( ) )
147
+ {
148
+ curCmdletCompatibilityMap [ key ] = true ;
149
+ }
150
+ }
151
+
152
+ private string GetSettingsDirectory ( )
153
+ {
134
154
// Find the compatibility files in Settings folder
135
155
var path = this . GetType ( ) . GetTypeInfo ( ) . Assembly . Location ;
136
156
if ( String . IsNullOrWhiteSpace ( path ) )
137
157
{
138
- return ;
158
+ return null ;
139
159
}
140
160
141
161
var settingsPath = Path . Combine ( Path . GetDirectoryName ( path ) , "Settings" ) ;
@@ -147,10 +167,11 @@ private void SetupCmdletsDictionary()
147
167
settingsPath = Path . Combine ( Path . GetDirectoryName ( Path . GetDirectoryName ( path ) ) , "Settings" ) ;
148
168
if ( ! Directory . Exists ( settingsPath ) )
149
169
{
150
- return ;
170
+ return null ;
151
171
}
152
172
}
153
- ProcessDirectory ( settingsPath ) ;
173
+
174
+ return settingsPath ;
154
175
}
155
176
156
177
private bool GetVersionInfoFromPlatformString (
@@ -225,6 +246,26 @@ private void ProcessDirectory(string path)
225
246
226
247
psCmdletMap [ fileNameWithoutExt ] = GetCmdletsFromData ( JObject . Parse ( File . ReadAllText ( filePath ) ) ) ;
227
248
}
249
+
250
+ RemoveUnavailableKeys ( ) ;
251
+ }
252
+
253
+ private void RemoveUnavailableKeys ( )
254
+ {
255
+ var keysToRemove = new List < string > ( ) ;
256
+ foreach ( var key in platformSpecMap . Keys )
257
+ {
258
+ if ( ! psCmdletMap . ContainsKey ( key ) )
259
+ {
260
+ keysToRemove . Add ( key ) ;
261
+ }
262
+ }
263
+
264
+ foreach ( var key in keysToRemove )
265
+ {
266
+ platformSpecMap . Remove ( key ) ;
267
+ curCmdletCompatibilityMap . Remove ( key ) ;
268
+ }
228
269
}
229
270
230
271
private HashSet < string > GetCmdletsFromData ( dynamic deserializedObject )
0 commit comments