1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Introduce a printer interface for flux resource

If implemented, there will a common interface to print flux resource.

We are adding new way to print resource information e.g. diff of
objects.

Signed-off-by: Soule BA <soule@weave.works>
This commit is contained in:
Soule BA
2022-03-07 12:05:53 +01:00
parent 307309504b
commit 7359e63960
6 changed files with 171 additions and 30 deletions

View File

@@ -33,6 +33,7 @@ import (
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/flux2/internal/utils"
"github.com/fluxcd/flux2/pkg/printers"
)
type deriveType func(runtime.Object) (summarisable, error)
@@ -177,7 +178,10 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
return err
}
utils.PrintTable(cmd.OutOrStdout(), header, rows)
err = printers.TablePrinter(header).Print(cmd.OutOrStdout(), rows)
if err != nil {
return err
}
if getAll {
fmt.Println()
@@ -242,10 +246,16 @@ func watchUntil(ctx context.Context, w watch.Interface, get *getCommand) (bool,
return false, err
}
if firstIteration {
utils.PrintTable(os.Stdout, header, rows)
err = printers.TablePrinter(header).Print(os.Stdout, rows)
if err != nil {
return false, err
}
firstIteration = false
} else {
utils.PrintTable(os.Stdout, []string{}, rows)
err = printers.TablePrinter([]string{}).Print(os.Stdout, rows)
if err != nil {
return false, err
}
}
return false, nil