diff --git a/Engine/CommandInfoCache.cs b/Engine/CommandInfoCache.cs index 20fd211aa..042f43cfa 100644 --- a/Engine/CommandInfoCache.cs +++ b/Engine/CommandInfoCache.cs @@ -30,19 +30,16 @@ public CommandInfoCache(Helper pssaHelperInstance) /// Retrieve a command info object about a command. /// /// Name of the command to get a commandinfo object for. - /// The alias of the command to be used in the cache key. If not given, uses the command name. /// What types of command are needed. If omitted, all types are retrieved. /// - public CommandInfo GetCommandInfo(string commandName, string aliasName = null, CommandTypes? commandTypes = null) + public CommandInfo GetCommandInfo(string commandName, CommandTypes? commandTypes = null) { if (string.IsNullOrWhiteSpace(commandName)) { return null; } - // If alias name is given, we store the entry under that, but search with the command name - var key = new CommandLookupKey(aliasName ?? commandName, commandTypes); - + var key = new CommandLookupKey(commandName, commandTypes); // Atomically either use PowerShell to query a command info object, or fetch it from the cache return _commandInfoCache.GetOrAdd(key, new Lazy(() => GetCommandInfoInternal(commandName, commandTypes))).Value; } @@ -60,7 +57,7 @@ public CommandInfo GetCommandInfoLegacy(string commandOrAliasName, CommandTypes? return string.IsNullOrEmpty(commandName) ? GetCommandInfo(commandOrAliasName, commandTypes: commandTypes) - : GetCommandInfo(commandName, aliasName: commandOrAliasName, commandTypes: commandTypes); + : GetCommandInfo(commandName, commandTypes: commandTypes); } /// diff --git a/Engine/Helper.cs b/Engine/Helper.cs index a3009a7ef..e51eb94ae 100644 --- a/Engine/Helper.cs +++ b/Engine/Helper.cs @@ -402,7 +402,7 @@ public HashSet GetExportedFunction(Ast ast) IEnumerable cmdAsts = ast.FindAll(item => item is CommandAst && exportFunctionsCmdlet.Contains((item as CommandAst).GetCommandName(), StringComparer.OrdinalIgnoreCase), true); - CommandInfo exportMM = Helper.Instance.GetCommandInfoLegacy("export-modulemember", CommandTypes.Cmdlet); + CommandInfo exportMM = Helper.Instance.GetCommandInfo("export-modulemember", CommandTypes.Cmdlet); // switch parameters IEnumerable switchParams = (exportMM != null) ? exportMM.Parameters.Values.Where(pm => pm.SwitchParameter) : Enumerable.Empty(); @@ -661,31 +661,6 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositiona return moreThanTwoPositional ? argumentsWithoutProcedingParameters > 2 : argumentsWithoutProcedingParameters > 0; } - - /// - /// Get a CommandInfo object of the given command name - /// - /// Returns null if command does not exists - private CommandInfo GetCommandInfoInternal(string cmdName, CommandTypes? commandType) - { - using (var ps = System.Management.Automation.PowerShell.Create()) - { - var psCommand = ps.AddCommand("Get-Command") - .AddParameter("Name", cmdName) - .AddParameter("ErrorAction", "SilentlyContinue"); - - if(commandType!=null) - { - psCommand.AddParameter("CommandType", commandType); - } - - var commandInfo = psCommand.Invoke() - .FirstOrDefault(); - - return commandInfo; - } - } - /// /// Legacy method, new callers should use instead. /// Given a command's name, checks whether it exists. It does not use the passed in CommandTypes parameter, which is a bug.