File: doc.go

package info (click to toggle)
golang-github-containers-common 0.50.1%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,440 kB
  • sloc: makefile: 118; sh: 46
file content (73 lines) | stat: -rw-r--r-- 1,795 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Package report provides helper structs/methods/funcs for formatting output

To format output for an array of structs:

ExamplePodman:
	headers := report.Headers(struct {
		ID string
	}{}, nil)

	f := report.New(os.Stdout, "Command Name")
	f, _ := f.Parse(report.OriginPodman, "{{range .}}{{.ID}}{{end}}")
	defer f.Flush()

	if f.RenderHeaders {
		f.Execute(headers)
	}
	f.Execute( map[string]string{
		"ID":"fa85da03b40141899f3af3de6d27852b",
	})

	// Output:
	// ID
	// fa85da03b40141899f3af3de6d27852b

ExampleUser:
	headers := report.Headers(struct {
		CID string
	}{}, map[string]string{"CID":"ID"})

	f, _ := report.New(os.Stdout, "Command Name").Parse(report.OriginUser, "table {{.CID}}")
	defer f.Flush()

	if f.RenderHeaders {
		t.Execute(t, headers)
	}
	t.Execute(t,map[string]string{
		"CID":"fa85da03b40141899f3af3de6d27852b",
	})

	// Output:
	// ID
	// fa85da03b40141899f3af3de6d27852b

Helpers:

	if report.IsJSON(cmd.Flag("format").Value.String()) {
		... process JSON and output
	}

	if report.HasTable(cmd.Flag("format").Value.String()) {
		... "table" keyword prefix in format text
	}

Template Functions:

The following template functions are added to the template when parsed:
	- join  strings.Join, {{join .Field separator}}
	- json encode field as JSON {{ json .Field }}
	- lower strings.ToLower {{ .Field | lower }}
	- pad add spaces as prefix and suffix {{ pad . 2 2 }}
	- split strings.Split {{ .Field | split }}
	- title strings.Title {{ .Field | title }}
	- truncate limit field length {{ truncate . 10 }}
	- upper strings.ToUpper {{ .Field | upper }}

report.Funcs() may be used to add additional template functions.
Adding an existing function will replace that function for the life of that template.


Note: Your code should not ignore errors
*/
package report