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

(#2591) Add headers to limit output commands #2856

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

corbob
Copy link
Member

@corbob corbob commented Oct 13, 2022

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)
  • 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
  • Tests to cover my changes, have been added
  • All new and existing tests passed.
  • PowerShell v2 compatibility checked.

@coveralls
Copy link

coveralls commented Oct 13, 2022

Coverage Status

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

@corbob
Copy link
Member Author

corbob commented Oct 14, 2022

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 corbob marked this pull request as ready for review October 31, 2022 18:30

public static class Options
{
public const string DISPLAY_HEADERS = "display-headers|use-headers";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not use aliases at all if we don't need to. Let's use --use-headers.

Copy link
Member

@JPRuskin JPRuskin Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would out[put]-headers / add-headers / display-headers be more accurate than use? Using the headers is something code further along the theoretical pipeline will do, not Choco (to me, at least).

Or just --headers? Skip verb debate 😅

@corbob corbob marked this pull request as draft March 6, 2024 05:09
@corbob
Copy link
Member Author

corbob commented Mar 6, 2024

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

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.

This also adds a StringResources static class that allows us to store
constant strings in and use them across the code to reduce duplication.
@gep13
Copy link
Member

gep13 commented Jun 21, 2024

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

@corbob corbob added the Requires Upstream Change Requires changes to a different location once issue is fixed or implemented label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Requires Upstream Change Requires changes to a different location once issue is fixed or implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a header row to --limit-output output
5 participants