-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transition code to allow migration to genericcli table printer (#317
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tableprinters | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fi-ts/cloudctl/cmd/output" | ||
"github.com/metal-stack/metal-lib/pkg/genericcli/printers" | ||
) | ||
|
||
type TablePrinter struct { | ||
t *printers.TablePrinter | ||
// TODO: we want to slowly migrate to the genericcli table printer | ||
// after everything was shifted to this package we can remove the "oldPrinter" | ||
oldPrinter printers.Printer | ||
} | ||
|
||
func New() *TablePrinter { | ||
return &TablePrinter{ | ||
oldPrinter: output.New(), | ||
} | ||
} | ||
|
||
func (t *TablePrinter) SetPrinter(printer *printers.TablePrinter) { | ||
t.t = printer | ||
} | ||
|
||
func (t *TablePrinter) ToHeaderAndRows(data any, wide bool) ([]string, [][]string, error) { | ||
// TODO: migrate old output package code to here | ||
// switch d := data.(type) { | ||
// default: | ||
// return nil, nil, t.oldPrinter.Print(data) | ||
// } | ||
// | ||
// fallback to old printer for as long as the migration takes: | ||
t.t.WithOut(io.Discard) | ||
return nil, nil, t.oldPrinter.Print(data) | ||
} |