-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Add Write-*
proxy for each Format-*
cmdlet
#20001
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
Comments
Out-*
proxy for each Format-*
cmdletWrite-*
proxy for each Format-*
cmdlet
Write-* prototype generator'Custom', 'List', 'Wide', 'Hex', 'Table' | Foreach-Object {
$FormatCommand = Get-Command Format-$_
$MetaData = [System.Management.Automation.CommandMetadata]$FormatCommand
$ProxyCommand = [System.Management.Automation.ProxyCommand]::Create($MetaData)
$AST = [System.Management.Automation.Language.Parser]::ParseInput($ProxyCommand, [ref]$Null, [ref]$Null)
$LastParam = $AST.ParamBlock.Parameters.Extent[-1]
$BeginBlock = $AST.BeginBlock.Extent
$ProcessBlock = $AST.ProcessBlock.Extent
$WriteCommand = $ProxyCommand.SubString(0, $LastParam.EndOffset) + @'
,
[switch]
${PassThru}
'@ + $ProxyCommand.SubString($LastParam.EndOffset, ($BeginBlock.StartOffset - $LastParam.EndOffset)) + @'
begin
{
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
if ($PSBoundParameters.TryGetValue('PassThru', [ref]$outBuffer))
{
$Null = $PSBoundParameters.Remove('PassThru')
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Format-
'@ + $_ + @'
', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = { & $wrappedCmd @PSBoundParameters | Out-Host }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}
'@ + $ProxyCommand.SubString($BeginBlock.EndOffset, ($ProcessBlock.StartOffset - $BeginBlock.EndOffset)) + @'
process
{
try {
if ($PassThru) { $_ }
$steppablePipeline.Process($_)
} catch {
throw
}
}
'@ + $ProxyCommand.SubString($ProcessBlock.EndOffset)
$Null = New-Item -Path Function:\ -Name Write-$_ -Value $WriteCommand -Force
} gci *.txt | Write-List -PassThru | Get-Item # or: ... | Remove-Item
|
@iRon7, wouldn't the implementation of #19827 facilitate this use case, at least with the default formatting? (And, as stated in the linked issue, instead of # Print the file-info objects to the terminal while also passing them through to the pipeline.
Get-ChildItem .\ -Include *.jpg | Tee-Object -Console | Remove-Item -Force -Recurse -WhatIf For other formatting and possibly other data processing, @dkaszews' yet-to-be-fully-fleshed-out |
That is correct for |
I have closed this purpose as it is now covered by the #20133 a common ... | Format-Table -Tee | ... |
Uh oh!
There was an error while loading. Please reload this page.
Summary of the new feature / enhancement
To avoid avoid wrapping cmdlet pipelines and better support a single pipeline, it would helpful to tee formatted data directly to the host and continue with the input objects.
This further ties into the Feature Request / Idea: #19989 -PassThru as common parameter followed up by #20133 A common -Reprocess parameter for passing through the current input item
Proposed technical implementation details (optional)
For each
Format-*
:There could an
Write-*
cmdlet:Which might be a simply proxy command which an additional
-PassThru
parameter.As questioned here: Powershell pipeline both remove-item and call function
This will allow for pipelines like (wishful thinking):
Caveat:
The text was updated successfully, but these errors were encountered: