Skip to content

Commit

Permalink
imagefilter: implement short version being non-yaml
Browse files Browse the repository at this point in the history
To avoid confusions and clean up implementation, there will
be this version, a condensed output in text-only format, as well
as a followup PR implementing a proper `yaml` output with
a `yaml` library.
  • Loading branch information
schuellerf authored and supakeen committed Feb 27, 2025
1 parent 245e0ed commit c1aee15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 2 additions & 8 deletions pkg/imagefilter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ type textShortResultsFormatter struct{}
func (*textShortResultsFormatter) Output(w io.Writer, all []Result) error {
var errs []error

// deliberately break the yaml until the feature is stable, there
// are open questions, e.g. how this relates to:
// https://github.com/osbuild/osbuild-composer/pull/4336
// which adds a similar but slightly different API
fmt.Fprint(w, "@WARNING - the output format is not stable yet and may change\n")

outputMap := make(map[string]map[string][]string)
for _, res := range all {
if _, ok := outputMap[res.Distro.Name()]; !ok {
Expand Down Expand Up @@ -133,10 +127,10 @@ func (*textShortResultsFormatter) Output(w io.Writer, all []Result) error {
for _, t := range types {
arches := outputMap[distro][t]
sort.Strings(arches)
typeArchPairs = append(typeArchPairs, fmt.Sprintf("%s: [ %s ]", t, strings.Join(arches, ", ")))
typeArchPairs = append(typeArchPairs, fmt.Sprintf("%s: %s", t, strings.Join(arches, ", ")))
}

if _, err := fmt.Fprintf(w, "%s:\n %s\n", distro, strings.Join(typeArchPairs, "\n ")); err != nil {
if _, err := fmt.Fprintf(w, "%s\n %s\n", distro, strings.Join(typeArchPairs, "\n ")); err != nil {
errs = append(errs, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/imagefilter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ func TestResultsFormatter(t *testing.T) {
{
"short",
[]string{"test-distro-1:qcow2:test_arch3"},
"@WARNING - the output format is not stable yet and may change\ntest-distro-1:\n qcow2: [ test_arch3 ]\n",
"test-distro-1\n qcow2: test_arch3\n",
},
{
"short",
[]string{
"test-distro-9:qcow2:test_arch3",
"test-distro-10:qcow2:test_arch3",
},
"@WARNING - the output format is not stable yet and may change\ntest-distro-9:\n qcow2: [ test_arch3 ]\ntest-distro-10:\n qcow2: [ test_arch3 ]\n",
"test-distro-9\n qcow2: test_arch3\ntest-distro-10\n qcow2: test_arch3\n",
},
{
"short",
[]string{
"test-distro-1:test_type:test_arch",
"test-distro-1:test_type:test_arch2",
},
"@WARNING - the output format is not stable yet and may change\ntest-distro-1:\n test_type: [ test_arch, test_arch2 ]\n",
"test-distro-1\n test_type: test_arch, test_arch2\n",
},
} {
res := make([]imagefilter.Result, len(tc.fakeResults))
Expand Down

0 comments on commit c1aee15

Please sign in to comment.