templateString pre-processes the format and returns it as a string for templating.
()
| 46 | // templateString pre-processes the format and returns it as a string |
| 47 | // for templating. |
| 48 | func (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. |
| 72 | type Context struct { |
no outgoing calls