ParseFormat converts a user-supplied string into a Format. Empty string and "table" both yield FormatTable; "json" and "tsv" are the other accepted values. Comparison is case-insensitive and ignores surrounding whitespace.
(s string)
| 61 | // "table" both yield FormatTable; "json" and "tsv" are the other accepted |
| 62 | // values. Comparison is case-insensitive and ignores surrounding whitespace. |
| 63 | func ParseFormat(s string) (Format, error) { |
| 64 | switch strings.ToLower(strings.TrimSpace(s)) { |
| 65 | case "", "table": |
| 66 | return FormatTable, nil |
| 67 | case "json": |
| 68 | return FormatJSON, nil |
| 69 | case "tsv": |
| 70 | return FormatTSV, nil |
| 71 | } |
| 72 | return 0, fmt.Errorf("invalid format %q (want table|json|tsv)", s) |
| 73 | } |
| 74 | |
| 75 | // ANSI color codes used by the color-aware renderers below. |
| 76 | const ( |
no outgoing calls