Documentation
¶
Overview ¶
Package report provides helper structs/methods/funcs for formatting output
To format output for an array of structs:
w := report.NewWriterDefault(os.Stdout)
defer w.Flush()
headers := report.Headers(struct {
ID string
}{}, nil)
t, _ := report.NewTemplate("command name").Parse("{{range .}}{{.ID}}{{end}}")
t.Execute(t, headers)
t.Execute(t, map[string]string{
"ID":"fa85da03b40141899f3af3de6d27852b",
})
// t.IsTable() == false
or
w := report.NewWriterDefault(os.Stdout)
defer w.Flush()
headers := report.Headers(struct {
CID string
}{}, map[string]string{
"CID":"ID"})
t, _ := report.NewTemplate("command name").Parse("table {{.CID}}")
t.Execute(t, headers)
t.Execute(t,map[string]string{
"CID":"fa85da03b40141899f3af3de6d27852b",
})
// t.IsTable() == true
Helpers:
if report.IsJSON(cmd.Flag("format").Value.String()) {
... process JSON and output
}
and
Note: Your code should not ignore errors
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Headers ¶
Headers queries the interface for field names. Array of map is returned to support range templates Note: unexported fields can be supported by adding field to overrides Note: It is left to the developer to write out said headers
Podman commands use the general rules of:
1) unchanged --format includes headers
2) --format '{{.ID}" # no headers
3) --format 'table {{.ID}}' # includes headers
func IsJSON ¶
JSONFormat test CLI --format string to be a JSON request
if report.IsJSON(cmd.Flag("format").Value.String()) {
... process JSON and output
}
func NormalizeFormat ¶
NormalizeFormat reads given go template format provided by CLI and munges it into what we need
Types ¶
type Template ¶
Template embeds template.Template to add functionality to methods
func NewTemplate ¶
NewTemplate creates a new template object
type Writer ¶
Writer aliases tabwriter.Writer to provide Podman defaults
func NewWriter ¶
func NewWriter(output io.Writer, minwidth, tabwidth, padding int, padchar byte, flags uint) (*Writer, error)
NewWriter initializes a new report.Writer with given values
func NewWriterDefault ¶
NewWriterDefault initializes a new report.Writer with Podman defaults