diff --git a/docs/image-types/rhel8/google-gce.md b/docs/image-types/rhel8/google-gce.md index 3308ca818b..7e78f2c466 100644 --- a/docs/image-types/rhel8/google-gce.md +++ b/docs/image-types/rhel8/google-gce.md @@ -132,14 +132,14 @@ The high-level description of the workflow used to build RHEL Guest Images is as 4. Delete all created resources. RHEL Guest Images are imported with the following Guest OS features set: -* UEFI_COMPATIBLE -* VIRTIO_SCSI_MULTIQUEUE -* SEV_CAPABLE -* SEV_SNP_CAPABLE -* SEV_LIVE_MIGRATABLE -* SEV_LIVE_MIGRATABLE_V2 -* GVNIC -* IDPF +* `UEFI_COMPATIBLE` +* `VIRTIO_SCSI_MULTIQUEUE` +* `SEV_CAPABLE` +* `SEV_SNP_CAPABLE` +* `SEV_LIVE_MIGRATABLE` +* `SEV_LIVE_MIGRATABLE_V2` +* `GVNIC` +* `IDPF` [daisy-tool]: https://github.com/GoogleCloudPlatform/compute-image-tools/tree/master/daisy diff --git a/pkg/imagefilter/formatter.go b/pkg/imagefilter/formatter.go index cf8245392a..3ab37ac9cb 100644 --- a/pkg/imagefilter/formatter.go +++ b/pkg/imagefilter/formatter.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "io" + "sort" + "strings" ) // OutputFormat contains the valid output formats for formatting results @@ -15,6 +17,7 @@ const ( OutputFormatText OutputFormat = "text" OutputFormatJSON OutputFormat = "json" OutputFormatTextShell OutputFormat = "shell" + OutputFormatTextShort OutputFormat = "short" ) // ResultFormatter will format the given result list to the given io.Writer @@ -31,6 +34,8 @@ func NewResultsFormatter(format OutputFormat) (ResultsFormatter, error) { return &jsonResultsFormatter{}, nil case OutputFormatTextShell: return &shellResultsFormatter{}, nil + case OutputFormatTextShort: + return &textShortResultsFormatter{}, nil default: return nil, fmt.Errorf("unsupported formatter %q", format) } @@ -77,6 +82,51 @@ func (*shellResultsFormatter) Output(w io.Writer, all []Result) error { return nil } +type textShortResultsFormatter struct{} + +func (*textShortResultsFormatter) Output(w io.Writer, all []Result) error { + var errs []error + + outputMap := make(map[string]map[string][]string) + for _, res := range all { + if _, ok := outputMap[res.Distro.Name()]; !ok { + outputMap[res.Distro.Name()] = make(map[string][]string) + } + outputMap[res.Distro.Name()][res.ImgType.Name()] = append(outputMap[res.Distro.Name()][res.ImgType.Name()], res.Arch.Name()) + } + + // Sort and prepare output + var distros []string + for distro := range outputMap { + distros = append(distros, distro) + } + sort.Strings(distros) + + for _, distro := range distros { + var types []string + for t := range outputMap[distro] { + types = append(types, t) + } + sort.Strings(types) + + var typeArchPairs []string + for _, t := range types { + arches := outputMap[distro][t] + sort.Strings(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 { + errs = append(errs, err) + } + } + if len(errs) > 0 { + return errors.Join(errs...) + } + + return nil +} + type jsonResultsFormatter struct{} type distroResultJSON struct { diff --git a/pkg/imagefilter/formatter_test.go b/pkg/imagefilter/formatter_test.go index 121f2cf26c..3d43fc70b8 100644 --- a/pkg/imagefilter/formatter_test.go +++ b/pkg/imagefilter/formatter_test.go @@ -70,6 +70,27 @@ func TestResultsFormatter(t *testing.T) { []string{"test-distro-1:qcow2:test_arch3"}, "qcow2 --distro test-distro-1 --arch test_arch3\n", }, + { + "short", + []string{"test-distro-1:qcow2:test_arch3"}, + "test-distro-1:\n qcow2: [ test_arch3 ]\n", + }, + { + "short", + []string{ + "test-distro-1:qcow2:test_arch3", + "test-distro-2:qcow2:test_arch3", + }, + "test-distro-1:\n qcow2: [ test_arch3 ]\ntest-distro-2:\n qcow2: [ test_arch3 ]\n", + }, + { + "short", + []string{ + "test-distro-1:test_type:test_arch", + "test-distro-1:test_type:test_arch2", + }, + "test-distro-1:\n test_type: [ test_arch, test_arch2 ]\n", + }, } { res := make([]imagefilter.Result, len(tc.fakeResults)) for i, resultSpec := range tc.fakeResults {