PrintTableToStdOut returns err when rendering fails
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
2cf02a4ca9
commit
587b318d1f
3 changed files with 17 additions and 10 deletions
|
|
@ -18,9 +18,10 @@ import (
|
|||
func NewInspectCmd(f *cmdutil.Factory, runF func(*Options) error) *cobra.Command {
|
||||
opts := &Options{}
|
||||
inspectCmd := &cobra.Command{
|
||||
Use: "inspect [<file path> | oci://<OCI image URI>] --bundle <path-to-bundle>",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Short: "Inspect a sigstore bundle",
|
||||
Use: "inspect [<file path> | oci://<OCI image URI>] --bundle <path-to-bundle>",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Hidden: true,
|
||||
Short: "Inspect a sigstore bundle",
|
||||
Long: heredoc.Docf(`
|
||||
Inspect a downloaded Sigstore bundle for a given artifact.
|
||||
|
||||
|
|
@ -144,7 +145,9 @@ func runInspect(opts *Options) error {
|
|||
|
||||
rows := make([][]string, 1)
|
||||
rows[0] = jsonResults
|
||||
opts.Logger.PrintTableToStdOut(nil, rows)
|
||||
if err = opts.Logger.PrintTableToStdOut(nil, rows); err != nil {
|
||||
return fmt.Errorf("failed to print output as JSON: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -155,7 +158,9 @@ func runInspect(opts *Options) error {
|
|||
}
|
||||
|
||||
headerRow := []string{"Repo Name", "Repo ID", "Org Name", "Org ID", "Workflow ID"}
|
||||
opts.Logger.PrintTableToStdOut(headerRow, details)
|
||||
if err = opts.Logger.PrintTableToStdOut(headerRow, details); err != nil {
|
||||
return fmt.Errorf("failed to print output as table: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package logging
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/cli/cli/v2/pkg/iostreams"
|
||||
"github.com/cli/go-gh/v2/pkg/tableprinter"
|
||||
|
|
@ -69,9 +68,9 @@ 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) {
|
||||
func (l *Logger) PrintTableToStdOut(headers []string, rows [][]string) error {
|
||||
if rows == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
t := tableprinter.New(l.IO.Out, l.IO.IsStdoutTTY(), l.IO.TerminalWidth())
|
||||
|
||||
|
|
@ -88,6 +87,7 @@ func (l *Logger) PrintTableToStdOut(headers []string, rows [][]string) {
|
|||
}
|
||||
|
||||
if err := t.Render(); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,7 +210,9 @@ func runVerify(opts *Options) error {
|
|||
|
||||
rows := make([][]string, 1)
|
||||
rows[0] = jsonResults
|
||||
opts.Logger.PrintTableToStdOut(nil, rows)
|
||||
if err := opts.Logger.PrintTableToStdOut(nil, rows); err != nil {
|
||||
return fmt.Errorf("failed to print JSON output")
|
||||
}
|
||||
}
|
||||
|
||||
// All attestations passed verification and policy evaluation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue