MCPcopy Index your code
hub / github.com/docker/cli / templateString

Method templateString

cli/command/formatter/formatter.go:48–69  ·  view source on GitHub ↗

templateString pre-processes the format and returns it as a string for templating.

()

Source from the content-addressed store, hash-verified

46// templateString pre-processes the format and returns it as a string
47// for templating.
48func (f Format) templateString() string {
49 out := string(f)
50 switch out {
51 case TableFormatKey:
52 // A bare "--format table" should already be handled before we
53 // hit this; a literal "table" here means a custom "table" format
54 // without template.
55 return ""
56 case JSONFormatKey:
57 // "--format json" only; not JSON formats ("--format '{{json .Field}}'").
58 return JSONFormat
59 }
60
61 // "--format 'table {{.Field}}\t{{.Field}}'" -> "{{.Field}}\t{{.Field}}"
62 if after, isTable := strings.CutPrefix(out, TableFormatKey); isTable {
63 out = after
64 }
65
66 out = strings.Trim(out, " ") // trim spaces, but preserve other whitespace.
67 out = strings.NewReplacer(`\t`, "\t", `\n`, "\n").Replace(out)
68 return out
69}
70
71// Context contains information required by the formatter to print the output as desired.
72type Context struct {

Callers 2

TestFormatFunction · 0.80
parseFormatMethod · 0.80

Calls

no outgoing calls

Tested by 1

TestFormatFunction · 0.64