Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete GetCommandInfoLegacy method and use GetCommandInfo instead #1387

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Engine/CommandInfoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,6 @@ public CommandInfo GetCommandInfo(string commandName, CommandTypes? commandTypes
return _commandInfoCache.GetOrAdd(key, new Lazy<CommandInfo>(() => GetCommandInfoInternal(commandName, commandTypes))).Value;
}

/// <summary>
/// Retrieve a command info object about a command.
/// </summary>
/// <param name="commandName">Name of the command to get a commandinfo object for.</param>
/// <param name="commandTypes">What types of command are needed. If omitted, all types are retrieved.</param>
/// <returns></returns>
[Obsolete("Alias lookup is expensive and should not be relied upon for command lookup")]
public CommandInfo GetCommandInfoLegacy(string commandOrAliasName, CommandTypes? commandTypes = null)
{
string commandName = _helperInstance.GetCmdletNameFromAlias(commandOrAliasName);

return string.IsNullOrEmpty(commandName)
? GetCommandInfo(commandOrAliasName, commandTypes: commandTypes)
: GetCommandInfo(commandName, commandTypes: commandTypes);
}

/// <summary>
/// Get a CommandInfo object of the given command name
Expand Down
14 changes: 0 additions & 14 deletions Engine/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,20 +667,6 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositiona
return moreThanTwoPositional ? argumentsWithoutProcedingParameters > 2 : argumentsWithoutProcedingParameters > 0;
}

/// <summary>
/// Legacy method, new callers should use <see cref="GetCommandInfo"/> instead.
/// Given a command's name, checks whether it exists. It does not use the passed in CommandTypes parameter, which is a bug.
/// But existing method callers are already depending on this behaviour and therefore this could not be simply fixed.
/// It also populates the commandInfoCache which can have side effects in some cases.
/// </summary>
/// <param name="name">Command Name.</param>
/// <param name="commandType">Not being used.</param>
/// <returns></returns>
[Obsolete]
public CommandInfo GetCommandInfoLegacy(string name, CommandTypes? commandType = null)
{
return CommandInfoCache.GetCommandInfoLegacy(commandOrAliasName: name, commandTypes: commandType);
}

/// <summary>
/// Given a command's name, checks whether it exists.
Expand Down
2 changes: 1 addition & 1 deletion Rules/UseCmdletCorrectly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private bool MandatoryParameterExists(CommandAst cmdAst)
{
#region Compares parameter list and mandatory parameter list.

CommandInfo cmdInfo = Helper.Instance.GetCommandInfoLegacy(cmdAst.GetCommandName());
CommandInfo cmdInfo = Helper.Instance.GetCommandInfo(cmdAst.GetCommandName());

// If we can't resolve the command or it's not a cmdlet, we are done
if (cmdInfo == null || (cmdInfo.CommandType != System.Management.Automation.CommandTypes.Cmdlet))
Expand Down
2 changes: 1 addition & 1 deletion Rules/UseShouldProcessCorrectly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private bool SupportsShouldProcess(string cmdName)
return false;
}

var cmdInfo = Helper.Instance.GetCommandInfoLegacy(cmdName);
var cmdInfo = Helper.Instance.GetCommandInfo(cmdName);
if (cmdInfo == null)
{
return false;
Expand Down