From 24412d20729be860c6d8524edc7b9290f034a200 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Thu, 14 Mar 2024 20:00:58 -0600 Subject: [PATCH] remove unneeded table printer method Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/inspect/inspect.go | 18 +++++++++++++++--- pkg/cmd/attestation/logging/logger.go | 14 -------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pkg/cmd/attestation/inspect/inspect.go b/pkg/cmd/attestation/inspect/inspect.go index abf5eb7fd..2df6ff858 100644 --- a/pkg/cmd/attestation/inspect/inspect.go +++ b/pkg/cmd/attestation/inspect/inspect.go @@ -10,6 +10,7 @@ import ( "github.com/cli/cli/v2/pkg/cmd/attestation/logging" "github.com/cli/cli/v2/pkg/cmd/attestation/verification" "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/cli/cli/v2/internal/tableprinter" "github.com/MakeNowJust/heredoc" "github.com/spf13/cobra" @@ -127,6 +128,7 @@ func runInspect(opts *Options) error { "Successfully verified all attestations against Sigstore!\n\n", )) + // If true, print results as a slice of JSON objects if opts.JsonResult { details, err := getAttestationDetails(res.VerifyResults) if err != nil { @@ -147,14 +149,24 @@ func runInspect(opts *Options) error { return nil } + // otherwise, print results in a table details, err := getDetailsAsSlice(res.VerifyResults) if err != nil { return fmt.Errorf("failed to parse attestation details: %w", err) } - headerRow := []string{"Repo Name", "Repo ID", "Org Name", "Org ID", "Workflow ID"} - if err = opts.Logger.PrintTableToStdOut(headerRow, details); err != nil { - return fmt.Errorf("failed to print output as table: %w", err) + headers := []string{"Repo Name", "Repo ID", "Org Name", "Org ID", "Workflow ID"} + t := tableprinter.New(opts.Logger.IO, tableprinter.WithHeader(headers...)) + + for _, row := range details { + for _, field := range row { + t.AddField(field, tableprinter.WithTruncate(nil)) + } + t.EndRow() + } + + if err = t.Render(); err != nil { + return fmt.Errorf("failed to print output: %w", err) } return nil diff --git a/pkg/cmd/attestation/logging/logger.go b/pkg/cmd/attestation/logging/logger.go index 55c23a164..c82cbea06 100644 --- a/pkg/cmd/attestation/logging/logger.go +++ b/pkg/cmd/attestation/logging/logger.go @@ -3,7 +3,6 @@ package logging import ( "fmt" - "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/pkg/iostreams" ) @@ -67,16 +66,3 @@ func (l *Logger) VerbosePrintf(f string, v ...interface{}) (int, error) { return fmt.Fprintf(l.IO.ErrOut, f, v...) } - -func (l *Logger) PrintTableToStdOut(headers []string, rows [][]string) error { - t := tableprinter.New(l.IO, tableprinter.WithHeader(headers...)) - - for _, row := range rows { - for _, field := range row { - t.AddField(field, tableprinter.WithTruncate(nil)) - } - t.EndRow() - } - - return t.Render() -}