winget-cli
winget-cli copied to clipboard
avoiding truncating search/list result
Description of the new feature / enhancement
Currently, result of winget list
and winget search
is truncated for adjusting display size or 120 chars if output is redirected.
This causes the inconvenient which cannot be display full name,id,tags of apps which has long one(eg. Visual Studio family).
It cannot be avoided even if result is redirected to file because max width is currently hard coded to 120 in source if redirect.
So I'm glad if options which set max width or getting no truncated string is added(or output with another structured format like json,csv,xml?).
Proposed technical implementation details
No response
I'd like an option resulting in behavior similar to PowerShell's Format-Table -AutoSize
i.e. don't truncate anything, which requires computing widths based on the widest value for each and every field.
See https://github.com/microsoft/winget-cli/issues/2161
This would be solved by https://github.com/microsoft/winget-cli/issues/1753
To use the functionality of PowerShells' Format-Table -AutoSize
I would suggest using the winget PowerShell cmdlets and then just running the actual Format-Table -AutoSize
cmdlet. I don't think this has to be re-implemented in the winget CLI. The winget CLI will never have feature parity with all of PowerShells' built-in filtering, sorting and formatting capabilities.
The only open issue here is that output is truncated to a width of 120 characters when redirected to a file. I don't see the reason for that, textfiles don't care about the length of the lines stored in them. But maybe there is a good reason.
Indeed, a change where the truncation is removed when output is redirected (to a file, to a pipe) would IMVHO be the best solution.
@denelon what do you think?
We're working on rich PowerShell objects currently, so I would also suggest focusing the attention on the new cmdlets at this time.
WinGet defaults to 120 columns if it cannot get the value from the "consoleInfo". The top 50 lines of output are considered for formatting the table.
https://github.com/microsoft/winget-cli/blob/741955e48ce2f069ab323f71e40dd1326654e7ab/src/AppInstallerCLICore/TableOutput.h#L13-L30
WinGet defaults to 120 columns if it cannot get the value from the "consoleInfo". The top 50 lines of output are considered for formatting the table.
I know that Bill Gates never said the apocryphal quote, but I can't help myself:
120 columns ought to be Enough for Anyone! /s :)
What needs to be done to fix this? I am happy to help with the code. This is unbearable.
@g0t4 I think the PowerShell module helps in this case tremendously, but from a CLI perspective, I'd think about an argument and setting pair. Naming things is hard, but I could imagine "--no-truncate" & "--truncate" as arguments with a default setting of "truncate" that can be overridden via the CLI and an optional setting for "don't truncate" that can be overriddent via the CLI.
We could also make the "default" width a variable that consumes from an argument and settings.
Another option to consider is an "--output-width" with a value and corollary settings.
@denelon thanks for the suggestion, I prefer the output of Get-WinGetPackage
given I can customize that with my own formatting
@denelon thanks for the suggestion, I prefer the output of
Get-WinGetPackage
given I can customize that with my own formatting
this is the (powershell) way
@denelon thanks for the suggestion, I prefer the output of
Get-WinGetPackage
given I can customize that with my own formatting
Indeed, that's going the right / PowerShell way.
But when you come from the winget
CLI tool, discoverability is, er... far from obvious:
[Policy] Area-Output
"No one will ever need more than 640K ram" - Bill Gates, 1981
Actually, not Bill Gates.
i don't have Get-WinGetPackage in Windows 10 22H2, where do I get it ?
@josesa-xx
Install-Module -Name Microsoft.WinGet.Client
https://www.powershellgallery.com/packages/Microsoft.WinGet.Client
Thanks for the suggestion I was able to get a full list without truncation with command:
Get-WinGetPackage | Format-Table -AutoSize | Out-File -Width 500 -FilePath winget_packages_$env:COMPUTERNAME.txt