mirror of
https://github.com/containers/skopeo.git
synced 2025-06-26 14:52:36 +00:00
Use common library reporter
Signed-off-by: Christoph Blecker <cblecker@redhat.com>
This commit is contained in:
parent
371604ba27
commit
313f142c87
@ -6,8 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/common/pkg/retry"
|
"github.com/containers/common/pkg/retry"
|
||||||
@ -74,6 +72,7 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error)
|
|||||||
rawManifest []byte
|
rawManifest []byte
|
||||||
src types.ImageSource
|
src types.ImageSource
|
||||||
imgInspect *types.ImageInspectInfo
|
imgInspect *types.ImageInspectInfo
|
||||||
|
rpt *report.Formatter
|
||||||
data []any
|
data []any
|
||||||
)
|
)
|
||||||
ctx, cancel := opts.global.commandTimeoutContext()
|
ctx, cancel := opts.global.commandTimeoutContext()
|
||||||
@ -158,9 +157,13 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error)
|
|||||||
fmt.Fprintf(stdout, "%s\n", string(out))
|
fmt.Fprintf(stdout, "%s\n", string(out))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}"
|
rpt, err = report.New(stdout, "skopeo inspect").Parse(report.OriginUser, opts.format)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rpt.Flush()
|
||||||
data = append(data, config)
|
data = append(data, config)
|
||||||
err = printTmpl(stdout, row, data)
|
err = rpt.Execute(data)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing OCI-formatted configuration data to standard output: %w", err)
|
return fmt.Errorf("Error writing OCI-formatted configuration data to standard output: %w", err)
|
||||||
@ -235,19 +238,12 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error)
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}"
|
|
||||||
data = append(data, outputData)
|
|
||||||
return printTmpl(stdout, row, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func printTmpl(stdout io.Writer, row string, data []any) error {
|
rpt, err = report.New(stdout, "skopeo inspect").Parse(report.OriginUser, opts.format)
|
||||||
t, err := template.New("skopeo inspect").Parse(row)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(stdout, 8, 2, 2, ' ', 0)
|
defer rpt.Flush()
|
||||||
if err := t.Execute(w, data); err != nil {
|
data = append(data, outputData)
|
||||||
return err
|
return rpt.Execute(data)
|
||||||
}
|
|
||||||
return w.Flush()
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ Use docker daemon host at _host_ (`docker-daemon:` transport only)
|
|||||||
|
|
||||||
Format the output using the given Go template.
|
Format the output using the given Go template.
|
||||||
The keys of the returned JSON can be used as the values for the --format flag (see examples below).
|
The keys of the returned JSON can be used as the values for the --format flag (see examples below).
|
||||||
|
Supports the Go templating functions available at https://pkg.go.dev/github.com/containers/common/pkg/report#hdr-Template_Functions
|
||||||
|
|
||||||
**--help**, **-h**
|
**--help**, **-h**
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user