@@ -131,11 +131,31 @@ private void SetupCmdletsDictionary()
131131 return ;
132132 }
133133
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+ {
134154 // Find the compatibility files in Settings folder
135155 var path = this . GetType ( ) . GetTypeInfo ( ) . Assembly . Location ;
136156 if ( String . IsNullOrWhiteSpace ( path ) )
137157 {
138- return ;
158+ return null ;
139159 }
140160
141161 var settingsPath = Path . Combine ( Path . GetDirectoryName ( path ) , "Settings" ) ;
@@ -147,10 +167,11 @@ private void SetupCmdletsDictionary()
147167 settingsPath = Path . Combine ( Path . GetDirectoryName ( Path . GetDirectoryName ( path ) ) , "Settings" ) ;
148168 if ( ! Directory . Exists ( settingsPath ) )
149169 {
150- return ;
170+ return null ;
151171 }
152172 }
153- ProcessDirectory ( settingsPath ) ;
173+
174+ return settingsPath ;
154175 }
155176
156177 private bool GetVersionInfoFromPlatformString (
@@ -225,6 +246,26 @@ private void ProcessDirectory(string path)
225246
226247 psCmdletMap [ fileNameWithoutExt ] = GetCmdletsFromData ( JObject . Parse ( File . ReadAllText ( filePath ) ) ) ;
227248 }
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+ }
228269 }
229270
230271 private HashSet < string > GetCmdletsFromData ( dynamic deserializedObject )
0 commit comments