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

imagefilter: add SupportedOutputFormats #1168

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

schuellerf
Copy link
Contributor

@schuellerf schuellerf commented Jan 24, 2025

Convenience function for concise help output

(This is based on #1166 and #1167)

The last commit could be split off, it's not directly related to the implementation of SupportedOutputFormats just extends the tests

@schuellerf schuellerf requested a review from a team as a code owner January 24, 2025 16:15
@schuellerf schuellerf force-pushed the add-GetSupportedOutputFormats branch 3 times, most recently from 19a040d to 66d1982 Compare January 24, 2025 16:16
@schuellerf schuellerf marked this pull request as draft January 24, 2025 16:18
@schuellerf schuellerf force-pushed the add-GetSupportedOutputFormats branch from 66d1982 to ddda18f Compare January 24, 2025 16:33
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you! I like the idea of having the SupportedOutputFormats() helper. Some suggestions for the implementation inline.

pkg/imagefilter/formatter.go Outdated Show resolved Hide resolved
pkg/imagefilter/formatter.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Quick drive-by:

  1. the PR description should follow the convention: module: change (e.g. imagefilter: add SupportedOutputFormats)
  2. Rebasing this on top of main and dropping the diff for the "short" output would most likely get this merged much quicker as I feel "short" output will need some more design/discussion but this here is very nice and straightforward.

@schuellerf schuellerf changed the title Add get supported output formats imagefilter: add SupportedOutputFormats Jan 27, 2025
@schuellerf schuellerf force-pushed the add-GetSupportedOutputFormats branch 2 times, most recently from 392df90 to 3125747 Compare January 28, 2025 08:53
@schuellerf schuellerf marked this pull request as ready for review January 28, 2025 08:53
@schuellerf schuellerf requested a review from mvo5 January 28, 2025 08:53
@schuellerf schuellerf force-pushed the add-GetSupportedOutputFormats branch 2 times, most recently from a7a1dc6 to 192ae46 Compare January 29, 2025 11:15
pkg/imagefilter/formatter_test.go Outdated Show resolved Hide resolved
@@ -27,20 +29,28 @@ type ResultsFormatter interface {
Output(io.Writer, []Result) error
}

// NewResultFormatter will create a formatter based on the given format.
var supportedFormatterMap = map[string]ResultsFormatter{
Copy link
Member

@supakeen supakeen Jan 29, 2025

Choose a reason for hiding this comment

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

Two notes:

  1. We normally don't use Hungarian notation; e.g. writing the type (Map) in the variable name and personally I don't like it.
  2. The behavior here is slightly different because all key lookups now return the same instance of a formatter. Since formatters don't keep state (right now) this might be OK, just wanted to write it down as it's a behavioral change I think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the careful review. I think this is fine because currently the formatters are an empty map, once we add state the map would become a map[string]func() Foramtter most likely to generate the new things (we could do it today but see below).

A fun fact of go is that empty structs get optimized away by the go-compiler, so at least on my system:

func TestNewDifferentObj(t *testing.T) {
	fmt1, err := imagefilter.NewResultsFormatter(imagefilter.OutputFormatText)
	assert.NoError(t, err)
	fmt2, err := imagefilter.NewResultsFormatter(imagefilter.OutputFormatText)
	assert.NoError(t, err)
	assert.NotEqual(t, fmt1, fmt2)
}

is false even with the current implementation that creates a "new" formatter with every new() call.

This is a long winded way of saying, I'm okay with as it is but open for ideas.

Copy link
Member

@supakeen supakeen left a comment

Choose a reason for hiding this comment

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

Some minor questions and bits.

@supakeen
Copy link
Member

the PR description should follow the convention: module: change (e.g. imagefilter: add SupportedOutputFormats)

I noticed the commits are now prefixed with the full package path instead of the module name. I don't know how I feel about this :)

@schuellerf schuellerf force-pushed the add-GetSupportedOutputFormats branch from 192ae46 to 43c0183 Compare January 31, 2025 11:15
@schuellerf
Copy link
Contributor Author

oh - that shouldn't happen?
https://github.com/osbuild/images/actions/runs/13071656708/job/36474442726?pr=1168
we are supposed to support 1.22, right?

go: github.com/vmware/govmomi/[email protected] requires go >= 1.23; switching to go1.23.5
go: downloading go1.23.5 (linux/amd64)

should I downgrade that lib so it works with 1.22?

@@ -0,0 +1,3 @@
package imagefilter

var SupportedFormatterMap = supportedFormatters
Copy link
Member

Choose a reason for hiding this comment

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

SupportedFormatters (the type is already a map) is the only bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

grr - overlooked that one, thanks

Implements function to get a list of all supported output formats.
Add a test for the fail-case.
@schuellerf schuellerf force-pushed the add-GetSupportedOutputFormats branch from 43c0183 to 30c82fe Compare January 31, 2025 11:25
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants