Repository navigation
Commit ffba8a2
David Noble
make check passes.
DelimitedFormatter carries three attributes -- Separator, SuppressHeadings,
Raw -- and ships three presets, which is gcloud's shape: its csv and value
are one renderer differing in separator, heading, and quoting, with value
documented as "CSV with no heading and <TAB> separator instead of <COMMA>".
csv , heading RFC 4180 quoting spreadsheets
tsv tab no heading RFC 4180 quoting cut -f2, awk
value tab no heading raw text --jq already built
Quoting is what separates the last from the middle. A machine-parseable
format must quote a field containing its own delimiter or the row loses a
boundary; a raw renderer must not, or text a caller composed comes back
wearing quotes it did not write.
The formatter now accepts every shape rather than only rows-with-fields. A
non-sequence is one row -- `--jq '.count'` produces exactly that, and
refusing it made the filter stage incomplete. A slice of scalars is one
column with no header, since a scalar has no field to name. A byte slice is
one value rather than a sequence of numbers.
Two tests asserted refusals that are now supported shapes, and are rewritten
as Accepts with the reason recorded rather than deleted.
That folding fixed tsv as a side effect: `-o tsv` on a scalar said "expected
slice or array, got int64" before, because value was a separate
implementation rather than a preset of the same one. The redundancy was in
the implementation, not the name.
It also simplified what it touched. With scalars no longer an error case,
csvHeadersFromElements and csvRowFromElement always returned nil errors;
lint caught it, and both lost their error returns along with the handling at
three call sites.
TableFormatter shares that column inference -- HasHeaders, csv:"name"
overrides, csv:"-" skips, the map-key union -- so one value renders the same
columns as table, csv, or tsv, and only the presentation differs. A test
pins it, because divergent column logic is how one rendering ends up showing
a field the other hides.
Alignment is text/tabwriter's, which measures in RUNES. That is half of #741
fixed at the shared formatter rather than at each call site: a hand-rolled
%-30s counts bytes, so a row with a multi-byte character is short by the
difference and every column after it shifts. The test uses a 7-rune,
21-byte name and asserts the next column starts at the same rune offset on
both rows.
The set is csv, json, none, table, template=BODY, tsv, value, yaml.
Files renamed: csv.go and its tests hold three presets now, not one format.
1 parent c946d7a commit ffba8a2
8 files changed
Lines changed: 378 additions & 204 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
15 | 16 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
31 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
32 | 40 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
37 | 44 | | |
38 | | - | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | | - | |
42 | | - | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | | - | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | | - | |
50 | | - | |
| 59 | + | |
| 60 | + | |
51 | 61 | | |
52 | | - | |
| 62 | + | |
53 | 63 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 64 | + | |
| 65 | + | |
57 | 66 | | |
58 | 67 | | |
59 | | - | |
60 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
61 | 84 | | |
62 | 85 | | |
63 | 86 | | |
| |||
69 | 92 | | |
70 | 93 | | |
71 | 94 | | |
72 | | - | |
| 95 | + | |
73 | 96 | | |
74 | 97 | | |
75 | 98 | | |
76 | 99 | | |
77 | 100 | | |
78 | 101 | | |
79 | 102 | | |
80 | | - | |
| 103 | + | |
81 | 104 | | |
82 | 105 | | |
83 | 106 | | |
84 | 107 | | |
85 | 108 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
92 | 112 | | |
93 | 113 | | |
| 114 | + | |
| 115 | + | |
94 | 116 | | |
95 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
96 | 123 | | |
97 | 124 | | |
98 | 125 | | |
| |||
101 | 128 | | |
102 | 129 | | |
103 | 130 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
108 | 163 | | |
| 164 | + | |
109 | 165 | | |
110 | 166 | | |
111 | 167 | | |
112 | | - | |
113 | | - | |
114 | | - | |
| 168 | + | |
115 | 169 | | |
116 | | - | |
| 170 | + | |
117 | 171 | | |
118 | 172 | | |
119 | 173 | | |
120 | 174 | | |
121 | 175 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 176 | + | |
127 | 177 | | |
128 | 178 | | |
129 | 179 | | |
| |||
149 | 199 | | |
150 | 200 | | |
151 | 201 | | |
152 | | - | |
| 202 | + | |
153 | 203 | | |
154 | 204 | | |
155 | 205 | | |
156 | 206 | | |
157 | 207 | | |
158 | | - | |
| 208 | + | |
159 | 209 | | |
160 | 210 | | |
161 | | - | |
| 211 | + | |
162 | 212 | | |
163 | 213 | | |
164 | | - | |
| 214 | + | |
| 215 | + | |
165 | 216 | | |
166 | 217 | | |
167 | 218 | | |
| |||
229 | 280 | | |
230 | 281 | | |
231 | 282 | | |
232 | | - | |
| 283 | + | |
233 | 284 | | |
234 | 285 | | |
235 | 286 | | |
236 | 287 | | |
237 | 288 | | |
238 | | - | |
| 289 | + | |
239 | 290 | | |
240 | 291 | | |
241 | | - | |
| 292 | + | |
242 | 293 | | |
243 | 294 | | |
244 | | - | |
| 295 | + | |
| 296 | + | |
245 | 297 | | |
246 | 298 | | |
247 | 299 | | |
| |||
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
198 | 203 | | |
199 | 204 | | |
200 | | - | |
201 | | - | |
202 | | - | |
| 205 | + | |
| 206 | + | |
203 | 207 | | |
204 | | - | |
205 | | - | |
| 208 | + | |
| 209 | + | |
206 | 210 | | |
207 | 211 | | |
208 | 212 | | |
209 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
210 | 218 | | |
211 | 219 | | |
212 | | - | |
213 | | - | |
214 | | - | |
| 220 | + | |
| 221 | + | |
215 | 222 | | |
216 | | - | |
217 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
218 | 230 | | |
219 | 231 | | |
220 | 232 | | |
| |||
243 | 255 | | |
244 | 256 | | |
245 | 257 | | |
246 | | - | |
| 258 | + | |
247 | 259 | | |
248 | 260 | | |
249 | 261 | | |
| |||
306 | 318 | | |
307 | 319 | | |
308 | 320 | | |
309 | | - | |
| 321 | + | |
310 | 322 | | |
311 | 323 | | |
312 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | | - | |
70 | | - | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
0 commit comments