@@ -152,15 +152,27 @@ def validate_manifest(manifest_path: Path, strict: bool) -> None:
152152 help = "Path to the manifest file to migrate (default: manifest.yaml)" ,
153153)
154154@click .option (
155- "--dry-run " ,
155+ "--in-place " ,
156156 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 " ,
158158)
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 :
160170 """Apply migrations to make a manifest file compatible with the latest version.
161171
162172 This command applies all necessary migrations to update the manifest file
163173 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.
164176 """
165177 try :
166178 original_manifest = yaml .safe_load (manifest_path .read_text ())
@@ -175,40 +187,47 @@ def migrate_manifest(manifest_path: Path, dry_run: bool) -> None:
175187 migration_handler = ManifestMigrationHandler (original_manifest )
176188 migrated_manifest = migration_handler .apply_migrations ()
177189
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
181192
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+ )
188200 return
189201
190202 current_cdk_version = metadata .version ("airbyte_cdk" )
191203 migrated_manifest ["version" ] = current_cdk_version
192204
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 )
196206
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 )
200215
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 )
212231
213232 except FileNotFoundError :
214233 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:
229248 help = "Path to the manifest file to normalize (default: manifest.yaml)" ,
230249)
231250@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" ,
233262 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 " ,
235264)
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 :
237268 """Normalize a manifest file by removing duplicated definitions and replacing them with references.
238269
239270 This command normalizes the manifest file by deduplicating elements and
240271 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.
241274 """
242275 try :
243276 original_manifest = yaml .safe_load (manifest_path .read_text ())
@@ -253,32 +286,41 @@ def normalize_manifest(manifest_path: Path, dry_run: bool) -> None:
253286 normalizer = ManifestNormalizer (original_manifest , schema )
254287 normalized_manifest = normalizer .normalize ()
255288
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
259293
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+ )
264299 return
265300
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 )
269302
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 )
271309
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 )
282324
283325 except FileNotFoundError :
284326 click .echo (f"❌ Error: Manifest file { manifest_path } not found" , err = True )
0 commit comments