From 8dfc33dd8e38536e5d5e75ed6fba65cf566cd756 Mon Sep 17 00:00:00 2001 From: Karl Isenberg Date: Wed, 9 Feb 2022 13:38:17 -0800 Subject: [PATCH] chore: rename printers to avoid stuttering --- .../event/{event_printer.go => printer.go} | 14 +++++++------- cmd/status/printers/printers.go | 4 ++-- .../table/{table_printer.go => printer.go} | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) rename cmd/status/printers/event/{event_printer.go => printer.go} (84%) rename cmd/status/printers/table/{table_printer.go => printer.go} (84%) diff --git a/cmd/status/printers/event/event_printer.go b/cmd/status/printers/event/printer.go similarity index 84% rename from cmd/status/printers/event/event_printer.go rename to cmd/status/printers/event/printer.go index 8ea82c0..c500911 100644 --- a/cmd/status/printers/event/event_printer.go +++ b/cmd/status/printers/event/printer.go @@ -14,15 +14,15 @@ import ( "sigs.k8s.io/cli-utils/pkg/object" ) -// EventPrinter implements the Printer interface and outputs the resource +// Printer implements the Printer interface and outputs the resource // status information as a list of events as they happen. -type EventPrinter struct { +type Printer struct { IOStreams genericclioptions.IOStreams } -// NewEventPrinter returns a new instance of the eventPrinter. -func NewEventPrinter(ioStreams genericclioptions.IOStreams) *EventPrinter { - return &EventPrinter{ +// NewPrinter returns a new instance of the eventPrinter. +func NewPrinter(ioStreams genericclioptions.IOStreams) *Printer { + return &Printer{ IOStreams: ioStreams, } } @@ -31,7 +31,7 @@ func NewEventPrinter(ioStreams genericclioptions.IOStreams) *EventPrinter { // until the channel is closed. The provided cancelFunc is consulted on // every event and is responsible for stopping the poller when appropriate. // This function will block. -func (ep *EventPrinter) Print(ch <-chan pollevent.Event, identifiers object.ObjMetadataSet, +func (ep *Printer) Print(ch <-chan pollevent.Event, identifiers object.ObjMetadataSet, cancelFunc collector.ObserverFunc) error { coll := collector.NewResourceStatusCollector(identifiers) // The actual work is done by the collector, which will invoke the @@ -52,7 +52,7 @@ func (ep *EventPrinter) Print(ch <-chan pollevent.Event, identifiers object.ObjM return err } -func (ep *EventPrinter) printStatusEvent(se pollevent.Event) { +func (ep *Printer) printStatusEvent(se pollevent.Event) { switch se.Type { case pollevent.ResourceUpdateEvent: id := se.Resource.Identifier diff --git a/cmd/status/printers/printers.go b/cmd/status/printers/printers.go index c23e985..5c63824 100644 --- a/cmd/status/printers/printers.go +++ b/cmd/status/printers/printers.go @@ -16,8 +16,8 @@ import ( func CreatePrinter(printerType string, ioStreams genericclioptions.IOStreams) (printer.Printer, error) { switch printerType { case "table": - return table.NewTablePrinter(ioStreams), nil + return table.NewPrinter(ioStreams), nil default: - return event.NewEventPrinter(ioStreams), nil + return event.NewPrinter(ioStreams), nil } } diff --git a/cmd/status/printers/table/table_printer.go b/cmd/status/printers/table/printer.go similarity index 84% rename from cmd/status/printers/table/table_printer.go rename to cmd/status/printers/table/printer.go index 2891c97..9bb93aa 100644 --- a/cmd/status/printers/table/table_printer.go +++ b/cmd/status/printers/table/printer.go @@ -18,22 +18,22 @@ const ( updateInterval = 1 * time.Second ) -// TablePrinter is an implementation of the Printer interface that outputs +// Printer is an implementation of the Printer interface that outputs // status information about resources in a table format with in-place updates. -type TablePrinter struct { +type Printer struct { IOStreams genericclioptions.IOStreams } -// NewTablePrinter returns a new instance of the tablePrinter. -func NewTablePrinter(ioStreams genericclioptions.IOStreams) *TablePrinter { - return &TablePrinter{ +// NewPrinter returns a new instance of the tablePrinter. +func NewPrinter(ioStreams genericclioptions.IOStreams) *Printer { + return &Printer{ IOStreams: ioStreams, } } // Print take an event channel and outputs the status events on the channel // until the channel is closed . -func (t *TablePrinter) Print(ch <-chan event.Event, identifiers object.ObjMetadataSet, +func (t *Printer) Print(ch <-chan event.Event, identifiers object.ObjMetadataSet, cancelFunc collector.ObserverFunc) error { coll := collector.NewResourceStatusCollector(identifiers) stop := make(chan struct{}) @@ -76,7 +76,7 @@ var columns = []table.ColumnDefinition{ // Print prints the table of resources with their statuses until the // provided stop channel is closed. -func (t *TablePrinter) runPrintLoop(coll *CollectorAdapter, stop <-chan struct{}) <-chan struct{} { +func (t *Printer) runPrintLoop(coll *CollectorAdapter, stop <-chan struct{}) <-chan struct{} { finished := make(chan struct{}) baseTablePrinter := table.BaseTablePrinter{