Commit cbfeb73
refactor(validate): inject Renderer via Kong's MapperValue interface
Reviewer pointed out that even with the polymorphic registry, the
OutputFormat string was still flowing through the command — we were
dispatching at every Render call site instead of resolving once at the
boundary. Subsequent passes worked through the implications: the
renderer types are stateless empty structs, so the map cache was
needless ceremony; the dispatch can collapse to a single fallible
boundary that takes a string-shaped format identifier and returns a
typed Renderer; and the natural place for that boundary is Kong itself,
which has first-class support for typed flag decoding.
Final shape:
* render: a single typed boundary.
* OutputFormat is a defined string type with three named constants
(OutputFormatText, OutputFormatJSON, OutputFormatYAML) so call
sites use symbolic names rather than embedded "json"/"yaml"
string literals.
* RendererFor(OutputFormat) (Renderer, error) is the only public
factory. Empty maps to text for ergonomics with zero-valued
config; any other unrecognised value returns an error.
* No format identifier or wrapper type is otherwise exposed;
downstream code receives only the Renderer interface and works
against the typed dependency.
* validate.Cmd: gained a private rendererFlag wrapper that implements
Kong's MapperValue interface, decoding --output straight into a
typed render.Renderer at parse time. Cmd.Output is now of type
rendererFlag (which embeds render.Renderer), so Cmd.Run calls
c.Output.Render(...) directly. AfterApply only sets the filesystem;
the renderer is already resolved by the time it runs. The wrapper
lives in this package, not in render, so the render package stays
free of any kong dependency and remains importable from non-CLI
consumers like crossplane-diff.
* Kong's enum:"" tag doesn't apply to MapperValue-backed fields, so
rendererFlag.Decode performs the validation itself; --help text
enumerates the valid values for users.
* render tests: switched to OutputFormat constants throughout. The
format-boundary test (TestRendererFor_FormatBoundary) covers the
named constants, the empty-string-as-text ergonomics, and unknown
rejection via OutputFormat("xml").
Smoke: `crossplane resource validate ... --output=json` emits valid
JSON; `--output=xml` is rejected by Kong with the wrapped Decode error
"--output: unknown output format: \"xml\"".
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>1 parent 050dafc commit cbfeb73
8 files changed
Lines changed: 294 additions & 288 deletions
File tree
- cmd/crossplane
- pkg/validate
- render
- validate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
39 | | - | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | | - | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
45 | 59 | | |
46 | 60 | | |
47 | 61 | | |
| |||
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
95 | 87 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | 88 | | |
105 | 89 | | |
106 | 90 | | |
107 | 91 | | |
108 | 92 | | |
109 | 93 | | |
110 | | - | |
| 94 | + | |
111 | 95 | | |
112 | 96 | | |
113 | 97 | | |
114 | 98 | | |
115 | 99 | | |
116 | | - | |
| 100 | + | |
117 | 101 | | |
118 | 102 | | |
119 | 103 | | |
120 | 104 | | |
121 | 105 | | |
122 | 106 | | |
123 | | - | |
| 107 | + | |
124 | 108 | | |
125 | 109 | | |
126 | 110 | | |
127 | 111 | | |
128 | 112 | | |
129 | | - | |
| 113 | + | |
130 | 114 | | |
131 | 115 | | |
132 | 116 | | |
| |||
143 | 127 | | |
144 | 128 | | |
145 | 129 | | |
146 | | - | |
147 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
148 | 135 | | |
149 | 136 | | |
| 137 | + | |
150 | 138 | | |
151 | 139 | | |
152 | | - | |
153 | | - | |
154 | | - | |
| 140 | + | |
155 | 141 | | |
156 | 142 | | |
157 | 143 | | |
158 | 144 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 145 | + | |
162 | 146 | | |
| 147 | + | |
163 | 148 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 149 | + | |
167 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
168 | 155 | | |
169 | 156 | | |
170 | 157 | | |
171 | 158 | | |
172 | | - | |
| 159 | + | |
173 | 160 | | |
174 | 161 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
180 | 166 | | |
181 | 167 | | |
182 | | - | |
183 | | - | |
| 168 | + | |
184 | 169 | | |
185 | | - | |
186 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
187 | 173 | | |
188 | | - | |
189 | | - | |
| 174 | + | |
| 175 | + | |
190 | 176 | | |
191 | 177 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
99 | 111 | | |
100 | | - | |
| 112 | + | |
101 | 113 | | |
102 | 114 | | |
103 | | - | |
| 115 | + | |
104 | 116 | | |
105 | 117 | | |
106 | 118 | | |
| |||
110 | 122 | | |
111 | 123 | | |
112 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
113 | 136 | | |
114 | 137 | | |
115 | 138 | | |
116 | 139 | | |
117 | 140 | | |
118 | 141 | | |
119 | | - | |
| 142 | + | |
120 | 143 | | |
121 | 144 | | |
122 | 145 | | |
123 | | - | |
124 | | - | |
| 146 | + | |
| 147 | + | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
| |||
136 | 159 | | |
137 | 160 | | |
138 | 161 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 162 | + | |
149 | 163 | | |
150 | | - | |
151 | 164 | | |
152 | 165 | | |
153 | 166 | | |
| |||
179 | 192 | | |
180 | 193 | | |
181 | 194 | | |
182 | | - | |
| 195 | + | |
183 | 196 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 197 | + | |
188 | 198 | | |
189 | | - | |
190 | | - | |
| 199 | + | |
| 200 | + | |
191 | 201 | | |
192 | 202 | | |
193 | 203 | | |
194 | 204 | | |
195 | 205 | | |
196 | 206 | | |
197 | | - | |
| 207 | + | |
198 | 208 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 209 | + | |
203 | 210 | | |
204 | | - | |
205 | | - | |
| 211 | + | |
| 212 | + | |
206 | 213 | | |
207 | 214 | | |
208 | 215 | | |
209 | 216 | | |
210 | 217 | | |
211 | 218 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
217 | 233 | | |
218 | | - | |
219 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
220 | 250 | | |
221 | 251 | | |
0 commit comments