@@ -152,15 +152,27 @@ def validate_manifest(manifest_path: Path, strict: bool) -> None:
152
152
help = "Path to the manifest file to migrate (default: manifest.yaml)" ,
153
153
)
154
154
@click .option (
155
- "--dry-run " ,
155
+ "--in-place " ,
156
156
is_flag = True ,
157
- help = "Show what changes would be made without actually modifying the file " ,
157
+ help = "Modify the file in place instead of printing to stdout " ,
158
158
)
159
- def migrate_manifest (manifest_path : Path , dry_run : bool ) -> None :
159
+ @click .option (
160
+ "--exit-non-zero" ,
161
+ is_flag = True ,
162
+ help = "Return non-zero exit code if the file is modified" ,
163
+ )
164
+ @click .option (
165
+ "--quiet" ,
166
+ is_flag = True ,
167
+ help = "Suppress output and return non-zero exit code if modified" ,
168
+ )
169
+ def migrate_manifest (manifest_path : Path , in_place : bool , exit_non_zero : bool , quiet : bool ) -> None :
160
170
"""Apply migrations to make a manifest file compatible with the latest version.
161
171
162
172
This command applies all necessary migrations to update the manifest file
163
173
to be compatible with the latest CDK version.
174
+
175
+ By default, the migrated manifest is printed to stdout. Use --in-place to modify the file directly.
164
176
"""
165
177
try :
166
178
original_manifest = yaml .safe_load (manifest_path .read_text ())
@@ -175,40 +187,47 @@ def migrate_manifest(manifest_path: Path, dry_run: bool) -> None:
175
187
migration_handler = ManifestMigrationHandler (original_manifest )
176
188
migrated_manifest = migration_handler .apply_migrations ()
177
189
178
- if migrated_manifest == original_manifest :
179
- click .echo (f"✅ Manifest { manifest_path } is already up to date - no migrations needed." )
180
- return
190
+ if quiet :
191
+ exit_non_zero = True
181
192
182
- if dry_run :
183
- click .echo (f"🔍 Dry run - changes that would be made to { manifest_path } :" )
184
- click .echo (
185
- " Migrations would be applied to update the manifest to the latest version."
186
- )
187
- click .echo (" Run without --dry-run to apply the changes." )
193
+ file_modified = migrated_manifest != original_manifest
194
+
195
+ if not file_modified :
196
+ if not quiet :
197
+ click .echo (
198
+ f"✅ Manifest { manifest_path } is already up to date - no migrations needed."
199
+ )
188
200
return
189
201
190
202
current_cdk_version = metadata .version ("airbyte_cdk" )
191
203
migrated_manifest ["version" ] = current_cdk_version
192
204
193
- manifest_path .write_text (
194
- yaml .dump (migrated_manifest , default_flow_style = False , sort_keys = False )
195
- )
205
+ migrated_yaml = yaml .dump (migrated_manifest , default_flow_style = False , sort_keys = False )
196
206
197
- click .echo (
198
- f"✅ Successfully migrated { manifest_path } to the latest version ({ current_cdk_version } )."
199
- )
207
+ if in_place :
208
+ manifest_path .write_text (migrated_yaml )
209
+ if not quiet :
210
+ click .echo (
211
+ f"✅ Successfully migrated { manifest_path } to the latest version ({ current_cdk_version } )."
212
+ )
213
+ else :
214
+ click .echo (migrated_yaml , nl = False )
200
215
201
- try :
202
- schema = _get_declarative_component_schema ()
203
- validate (migrated_manifest , schema )
204
- click .echo (f"✅ Migrated manifest { manifest_path } passes validation." )
205
- except ValidationError as e :
206
- click .echo (
207
- f"⚠️ Warning: Migrated manifest { manifest_path } still has validation issues:" ,
208
- err = True ,
209
- )
210
- click .echo (f" { e .message } " , err = True )
211
- click .echo (" Manual fixes may be required." , err = True )
216
+ if exit_non_zero and file_modified :
217
+ sys .exit (1 )
218
+
219
+ if in_place and not quiet :
220
+ try :
221
+ schema = _get_declarative_component_schema ()
222
+ validate (migrated_manifest , schema )
223
+ click .echo (f"✅ Migrated manifest { manifest_path } passes validation." )
224
+ except ValidationError as e :
225
+ click .echo (
226
+ f"⚠️ Warning: Migrated manifest { manifest_path } still has validation issues:" ,
227
+ err = True ,
228
+ )
229
+ click .echo (f" { e .message } " , err = True )
230
+ click .echo (" Manual fixes may be required." , err = True )
212
231
213
232
except FileNotFoundError :
214
233
click .echo (f"❌ Error: Manifest file { manifest_path } not found" , err = True )
@@ -229,15 +248,29 @@ def migrate_manifest(manifest_path: Path, dry_run: bool) -> None:
229
248
help = "Path to the manifest file to normalize (default: manifest.yaml)" ,
230
249
)
231
250
@click .option (
232
- "--dry-run" ,
251
+ "--in-place" ,
252
+ is_flag = True ,
253
+ help = "Modify the file in place instead of printing to stdout" ,
254
+ )
255
+ @click .option (
256
+ "--exit-non-zero" ,
257
+ is_flag = True ,
258
+ help = "Return non-zero exit code if the file is modified" ,
259
+ )
260
+ @click .option (
261
+ "--quiet" ,
233
262
is_flag = True ,
234
- help = "Show what changes would be made without actually modifying the file " ,
263
+ help = "Suppress output and return non-zero exit code if modified " ,
235
264
)
236
- def normalize_manifest (manifest_path : Path , dry_run : bool ) -> None :
265
+ def normalize_manifest (
266
+ manifest_path : Path , in_place : bool , exit_non_zero : bool , quiet : bool
267
+ ) -> None :
237
268
"""Normalize a manifest file by removing duplicated definitions and replacing them with references.
238
269
239
270
This command normalizes the manifest file by deduplicating elements and
240
271
creating references to shared components, making the manifest more maintainable.
272
+
273
+ By default, the normalized manifest is printed to stdout. Use --in-place to modify the file directly.
241
274
"""
242
275
try :
243
276
original_manifest = yaml .safe_load (manifest_path .read_text ())
@@ -253,32 +286,41 @@ def normalize_manifest(manifest_path: Path, dry_run: bool) -> None:
253
286
normalizer = ManifestNormalizer (original_manifest , schema )
254
287
normalized_manifest = normalizer .normalize ()
255
288
256
- if normalized_manifest == original_manifest :
257
- click .echo (f"✅ Manifest { manifest_path } is already normalized - no changes needed." )
258
- return
289
+ if quiet :
290
+ exit_non_zero = True
291
+
292
+ file_modified = normalized_manifest != original_manifest
259
293
260
- if dry_run :
261
- click .echo (f"🔍 Dry run - changes that would be made to { manifest_path } :" )
262
- click .echo (" Duplicated definitions would be removed and replaced with references." )
263
- click .echo (" Run without --dry-run to apply the changes." )
294
+ if not file_modified :
295
+ if not quiet :
296
+ click .echo (
297
+ f"✅ Manifest { manifest_path } is already normalized - no changes needed."
298
+ )
264
299
return
265
300
266
- manifest_path .write_text (
267
- yaml .dump (normalized_manifest , default_flow_style = False , sort_keys = False )
268
- )
301
+ normalized_yaml = yaml .dump (normalized_manifest , default_flow_style = False , sort_keys = False )
269
302
270
- click .echo (f"✅ Successfully normalized { manifest_path } ." )
303
+ if in_place :
304
+ manifest_path .write_text (normalized_yaml )
305
+ if not quiet :
306
+ click .echo (f"✅ Successfully normalized { manifest_path } ." )
307
+ else :
308
+ click .echo (normalized_yaml , nl = False )
271
309
272
- try :
273
- validate (normalized_manifest , schema )
274
- click .echo (f"✅ Normalized manifest { manifest_path } passes validation." )
275
- except ValidationError as e :
276
- click .echo (
277
- f"⚠️ Warning: Normalized manifest { manifest_path } has validation issues:" ,
278
- err = True ,
279
- )
280
- click .echo (f" { e .message } " , err = True )
281
- click .echo (" Manual fixes may be required." , err = True )
310
+ if exit_non_zero and file_modified :
311
+ sys .exit (1 )
312
+
313
+ if in_place and not quiet :
314
+ try :
315
+ validate (normalized_manifest , schema )
316
+ click .echo (f"✅ Normalized manifest { manifest_path } passes validation." )
317
+ except ValidationError as e :
318
+ click .echo (
319
+ f"⚠️ Warning: Normalized manifest { manifest_path } has validation issues:" ,
320
+ err = True ,
321
+ )
322
+ click .echo (f" { e .message } " , err = True )
323
+ click .echo (" Manual fixes may be required." , err = True )
282
324
283
325
except FileNotFoundError :
284
326
click .echo (f"❌ Error: Manifest file { manifest_path } not found" , err = True )
0 commit comments