choco icon indicating copy to clipboard operation
choco copied to clipboard

(#2591) Add headers to limit output commands

Open corbob opened this issue 3 years ago • 4 comments

Description Of Changes

When a user asks for limited output from Chocolatey, it is not uncommon to pipe that output to ConvertFrom-String or ConvertFrom-Csv and manually add headers to get back an object. This allows for getting a header row back so that the end user doesn't need to add their own headers and discern what they are.

Adds a new feature that allows the user to always display the headers if desired. This defaults to off so that we don't break any existing scripts.

Motivation and Context

Reduce the amount of work end users need to do in order to consume limited output.

Testing

Ran through the tests in the Vagrant test environment. This resulted in two failures that appear unrelated to my changes. I will investigate those further before marking this PR as ready.

NOTE: This will require Chocolatey Licensed Extension changes.

Change Types Made

  • [ ] Bug fix (non-breaking change)
  • [x] Feature / Enhancement (non-breaking change)
  • [ ] Breaking change (fix or feature that could cause existing functionality to change)
  • [ ] PowerShell code changes.

Related Issue

Fixes #2591

Change Checklist

  • [ ] Requires a change to the documentation
  • [ ] Documentation has been updated
  • [x] Tests to cover my changes, have been added
  • [ ] All new and existing tests passed.
  • [ ] PowerShell v2 compatibility checked.

corbob avatar Oct 13 '22 22:10 corbob

Coverage Status

Coverage remained the same at 27.719% when pulling 46e4a2dbfc722ce9e49583b3234173b3cf99a185 on corbob:add_headers into e35fe2b355592dc914cfe07a36abad5d1d133baa on chocolatey:develop.

coveralls avatar Oct 13 '22 22:10 coveralls

The tests added here failed on the pin output with a header due to it being overloaded I think... It might require some further investigation, and perhaps we should do that before merging this in?

For completeness this is the Test Kitchen output:

         Context Outputs headers for pin
           [+] Exits success (0) 4ms (2ms|2ms)
           [-] Displays appropriate header 5ms (4ms|1ms)
            Expected 'PackageID|Version', but got $null.
            at $ActualOutput | Should -Be $ExpectedHeaders, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-licensed-tests\chocolatey-tests\features\Headers.Tests.ps1:129
            at <ScriptBlock>, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-licensed-tests\chocolatey-tests\features\Headers.Tests.ps1:129

corbob avatar Oct 14 '22 00:10 corbob

Converting this back to draft as it requires quite a bit of rework and validation.

corbob avatar Mar 06 '24 05:03 corbob

@corbob I may have taken this for a quick spin, and rebased on the head of the develop branch. Just wanted to give you a heads up, so that you weren't surprised.

gep13 avatar Jun 21 '24 07:06 gep13