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

avoiding truncating search/list result #1653

Open
itn3000 opened this issue Oct 28, 2021 · 37 comments
Open

avoiding truncating search/list result #1653

itn3000 opened this issue Oct 28, 2021 · 37 comments
Labels
Area-Output Issue related to CLI output Issue-Feature This is a feature request for the Windows Package Manager client.

Comments

@itn3000
Copy link

itn3000 commented Oct 28, 2021

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

@itn3000 itn3000 added the Issue-Feature This is a feature request for the Windows Package Manager client. label Oct 28, 2021
@ghost ghost added the Needs-Triage Issue need to be triaged label Oct 28, 2021
@denelon denelon removed the Needs-Triage Issue need to be triaged label Oct 28, 2021
@sba923
Copy link

sba923 commented Aug 31, 2022

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 #2161

@jantari
Copy link

jantari commented Jan 7, 2023

This would be solved by #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.

@sba923
Copy link

sba923 commented Jan 21, 2023

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?

@denelon
Copy link
Contributor

denelon commented Jan 23, 2023

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.

namespace AppInstaller::CLI::Execution
{
namespace details
{
// Gets the column width of the console.
inline size_t GetConsoleWidth()
{
CONSOLE_SCREEN_BUFFER_INFO consoleInfo{};
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo))
{
return static_cast<size_t>(consoleInfo.dwSize.X);
}
else
{
return 120;
}
}
}

@halr9000
Copy link

halr9000 commented Feb 6, 2023

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
:)

@g0t4
Copy link

g0t4 commented May 19, 2023

What needs to be done to fix this? I am happy to help with the code. This is unbearable.

@denelon
Copy link
Contributor

denelon commented May 19, 2023

@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.

@g0t4
Copy link

g0t4 commented Jun 6, 2023

@denelon thanks for the suggestion, I prefer the output of Get-WinGetPackage given I can customize that with my own formatting

@halr9000
Copy link

@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

@sba923
Copy link

sba923 commented Jun 12, 2023

@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:

image

@Trenly
Copy link
Contributor

Trenly commented Jun 16, 2023

[Policy] Area-Output

@microsoft-github-policy-service microsoft-github-policy-service bot added the Area-Output Issue related to CLI output label Jun 16, 2023
@Fred-IV
Copy link

Fred-IV commented Jul 11, 2023

"No one will ever need more than 640K ram" - Bill Gates, 1981

@dertuxmalwieder
Copy link

Actually, not Bill Gates.

@josesa-xx
Copy link

i don't have Get-WinGetPackage in Windows 10 22H2, where do I get it ?

@jantari
Copy link

jantari commented Jul 9, 2024

@josesa-xx

Install-Module -Name Microsoft.WinGet.Client

https://www.powershellgallery.com/packages/Microsoft.WinGet.Client

@josesa-xx
Copy link

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

@kater-murr
Copy link

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

This doesn't work on my testing machine. (I get the same truncated output with max 120 chars.) Did you maybe change any settings or environment variables?

What I found is that the command

& winget list

formats the output to the maximal size of the console window. Up to 163 characters on my testing machine. So the omitted parts are obviously not just gone. But I can't find a way to catch all the output in a file or variable.

@sba923
Copy link

sba923 commented Jul 23, 2024

This works fine here, in PowerShell 7.4.3 running in Windows Terminal Preview 1.21.1772.0 with an intentionally low (53-char) console width. The resulting text file's lines are 211 characters wide.

image

@kater-murr
Copy link

This works fine here, in PowerShell 7.4.3

You are right. Thanks for the hint. It works in PowerShell 7.4.3, it doesn't in 5.1.19041.4648

Thanks to all of you.

@dertuxmalwieder
Copy link

I still wish that was right in PS, so it could be reliably used for scripting on other people's computers.

@Sebastian-Cerga
Copy link

Sebastian-Cerga commented Jul 24, 2024

Get-WinGetPackage | Format-Table -AutoSize (if terminal window is wide enough OR output to file using "| Out-File -Width 500 -FilePath winget_packages_$env:COMPUTERNAME.txt") are working fine on "PowerShell 7.5.0-preview.3".

Still wish this would have been default behaviour in "winget list"

@schittli

This comment was marked as off-topic.

@dertuxmalwieder
Copy link

dertuxmalwieder commented Jul 28, 2024

M$

Writing lik€ thi$ do€$ not h€lp your cau$€, pal.

@Marvodor
Copy link

As it seems to be really difficult to just not truncate the piped output of "winget list", can we please change the constant 120 to 255 or 65535 or anything else not completely too small?

@Marvodor
Copy link

Install-Module -Name Microsoft.WinGet.Client

The most obvious difference to "winget list" is the usage of three ASCII-dots "..." instead of an Unicode-ellipsis "…". The output is truncated anyway and I have a bad feeling because I had to install third-party-software from a source flagged as being unsecure.

PS‌ get-host says I am using Powershell version 5.1.19041.4648 although all Windows updates have been installed.

@sba923
Copy link

sba923 commented Jul 30, 2024

PS‌ get-host says I am using Powershell version 5.1.19041.4648 although all Windows updates have been installed.

PowerShell 7 is not an "update to Windows PowerShell 5.1" but kind of a "different product" that installs side-by-side and is not part of Windows (yet 😝).

@Marvodor
Copy link

PowerShell 7 is not an "update to Windows PowerShell 5.1" but kind of a "different product" that installs side-by-side and is not part of Windows (yet 😝).

Thank you, my old cmd file finally works as expected :-)

echo y|pwsh -c "install-Module Microsoft.WinGet.Client"
pwsh -c "get-WinGetPackage | format-table -autosize | out-file -width 1000 -filepath $env:liste"
if errorlevel 1 winget list>%liste%

@mominshaikhdevs
Copy link

@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 @Trenly, (adding #3071 too) whats the latest update on this?

@wykopx
Copy link

wykopx commented Aug 9, 2024

After 3 years since creation of this issue

the Name and the ID of installed apps are still truncated

winget list

image

There is a workaround to view full ID using this PowerShell command:

Get-WinGetPackage | Select Id

image

@mm6502
Copy link

mm6502 commented Oct 10, 2024

It should allow output in json or something...

@jantari
Copy link

jantari commented Oct 10, 2024

@mm6502 Get-WinGetPackage | ConvertTo-Json

@mm6502
Copy link

mm6502 commented Oct 10, 2024

@jantari
That is not very helpful in my scenario. I need the user to provide a list of software he has installed on his machine. He won't be able to install random stuff (due to permissions and skills). But I can ask him to provide a file generated by:
> winget list --output-format json --output-file the_list.txt

@sba923
Copy link

sba923 commented Oct 10, 2024

@jantari
That is not very helpful in my scenario. I need the user to provide a list of software he has installed on his machine. He won't be able to install random stuff (due to permissions and skills).

But you're assuming winget is present on their machine?

@mm6502
Copy link

mm6502 commented Oct 10, 2024

@jantari
You are looking for problems where there are not any. I know it is.

@josh-hemphill
Copy link

@sba923
But you're assuming winget is present on their machine?

I've been able to rely on winget being present on all new installs when I deploy systems, it's been shipping with windows for a while now... (And even Win Server 2025 seems will ship with it)

@jantari
Copy link

jantari commented Oct 10, 2024

@mm

@jantari You are looking for problems where there are not any. I know it is.

Hey, that wasn't me 😅

But we're bringing up a good point - why isn't the PowerShell module also preinstalled just like winget itself is? Many issues like this one show that the old DOS CLI just doesn't work for people.

@josh-hemphill

(And even Win Server 2025 seems will ship with it)

Unfortunately, only with the "Desktop Experience" installation. See the announcement and this issue.

@AltitudeApps
Copy link

AltitudeApps commented Feb 17, 2025

I just added a comment to the issue discussing the need for textual structured output, here: #1753

Most of it applies in this context, so I'll just paste most of what I typed over there:

I agree with the need for both JSON and CSV output, as well as simply providing arbitrarily wide text output which can be redirected to a file.

The original design philosophy of PowerShell included the ability to flexibly integrate other text-based command line tools seamlessly. Using PowerShell modules and .NET objects everywhere is NOT "the PowerShell way", it is just part of the PowerShell way.

A bespoke PowerShell module seems goofy when the winget CLI already does everything that I need it to do. Almost everything, that is. The winget CLI provides for all my needs, as long as I'm sitting in front of the console, watching what's printed after each command. I can widen my terminal and get full output. But try to redirect the perfectly good output to a file? Winget deliberately defeats me by truncating the strings, and now I discover that the project defies user requests to provide some sort of simple text output, which we could then pipe into whatever other tooling we might be needing to interact with.

Another scenario: sometimes I need to run winget in a cmd.exe session in a legacy console host. For instance, when I want to upgrade Windows Terminal and/or PowerShell 7.x itself. It makes things much less confusing when the items I'm upgrading aren't running at all.

It looks like one might be able to direct their attention to this portion of the code:

size_t consoleWidth = GetConsoleWidth();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Issue related to CLI output Issue-Feature This is a feature request for the Windows Package Manager client.
Projects
None yet
Development

No branches or pull requests