-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Summary of the new feature/enhancement
PowerShell has a rich formatting and output system that allows for multiple views to be defined for a given type. This is a powerful but under utilized feature due to view name discovery. The user is unaware of what views are available for a given type. There is Get-FormatData added in PSv3 to get imported format views but is a lot of work to just find out what view names exist in the system. To solve the discovery problem and increase usage of the diverse format views available, an argument completer should be added to the Format-* command -View parameter.
Proposed technical implementation details (optional)
This is a proof of concept for Format-Table -View parameter. It works when using the -InputObject parameter outside of the pipleline. Not sure if there is a way to get $fakeBoundParameters to be defined when using the pipleline. (If this needs to be a new issue I can open one)
$s = {
param ($commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameters)
$views = Get-FormatData -TypeName (@($fakeBoundParameters['InputObject'])[0].PSTypeNames -split '`r`n') |
Select-Object -ExpandProperty FormatViewDefinition |
Where-Object { $_.Control.GetType().Name -eq 'TableControl'} |
Select-Object -ExpandProperty Name
foreach ($view in $views) {
New-Object -Type System.Management.Automation.CompletionResult -ArgumentList $view, $view, "ParameterValue", $view
}
}
Register-ArgumentCompleter -CommandName Format-Table -ParameterName View -ScriptBlock $s