Skip to content

Fix piping more than one CommandInfo to Get-Command#10929

Merged
adityapatwardhan merged 2 commits intoPowerShell:masterfrom
SteveL-MSFT:getcommand-pipeline
Nov 7, 2019
Merged

Fix piping more than one CommandInfo to Get-Command#10929
adityapatwardhan merged 2 commits intoPowerShell:masterfrom
SteveL-MSFT:getcommand-pipeline

Conversation

@SteveL-MSFT
Copy link
Copy Markdown
Member

@SteveL-MSFT SteveL-MSFT commented Oct 29, 2019

PR Summary

Piping multiple CommandInfo to Get-Command only returns the first result. This is because during discovery of the command it internally builds a cache of commands it has already seen. On the second (or more) times ProcessRecord() is called, that cache is already filled with some results. If the requested CommandInfo (which binds to -Verb and -Noun) happens to be in that cache, then the cmdlet considers that a duplicate and doesn't return that result. The fix in this case is to clear the cache at the start of ProcessRecord() to treat each search as independent.

PR Context

Fix #10851

PR Checklist

@SteveL-MSFT
Copy link
Copy Markdown
Member Author

@PoshChan please retry linux

@PoshChan
Copy link
Copy Markdown
Collaborator

@SteveL-MSFT, successfully started retry of PowerShell-CI-Linux

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 30, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.6 milestone Oct 30, 2019
@adityapatwardhan adityapatwardhan merged commit ef64321 into PowerShell:master Nov 7, 2019
@mklement0
Copy link
Copy Markdown
Contributor

Unfortunately, this PR didn't fix all problems, because the following tests fail:

function foo {}; set-alias foo foo

(gcm -all foo | gcm).Count | Should -Be 2

(gcm -all foo | gcm).ComandType | Should -Be Alias, Function

@SteveL-MSFT
Copy link
Copy Markdown
Member Author

@mklement0 those are different issues not related to piping to Get-Command, please open a new issue for them

@SteveL-MSFT SteveL-MSFT deleted the getcommand-pipeline branch November 7, 2019 22:49
@mklement0
Copy link
Copy Markdown
Contributor

@SteveL-MSFT: These tests do pipe to Get-Command (whose built-in alias is gcm). In what way is this a different issue?

@mklement0
Copy link
Copy Markdown
Contributor

If it helps with getting this resolved, please see #11017

@SteveL-MSFT
Copy link
Copy Markdown
Member Author

SteveL-MSFT commented Nov 7, 2019

@mklement0 my mistake, I only saw the left side of the pipe. In anycase, the root cause is something different.

@ghost
Copy link
Copy Markdown

ghost commented Nov 21, 2019

🎉v7.0.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-Command doesn't recognize System.Management.Automation.CommandInfo (its own output type) as pipeline input

6 participants