@@ -394,29 +394,58 @@ def _update_workatoenv_files(old_name: str, new_name: str) -> list[Path]:
394394@profiles .command ()
395395@click .argument ("old_name" )
396396@click .argument ("new_name" )
397+ @click .option (
398+ "--output-mode" ,
399+ type = click .Choice (["table" , "json" ]),
400+ default = "table" ,
401+ help = "Output format: table (default) or json" ,
402+ )
403+ @click .option (
404+ "--yes" ,
405+ is_flag = True ,
406+ help = "Skip confirmation prompt" ,
407+ )
397408@handle_cli_exceptions
398409@inject
399410async def rename (
400411 old_name : str ,
401412 new_name : str ,
413+ output_mode : str = "table" ,
414+ yes : bool = False ,
402415 config_manager : ConfigManager = Provide [Container .config_manager ],
403416) -> None :
404417 """Rename a profile"""
405418 # Check if old profile exists
406419 old_profile = config_manager .profile_manager .get_profile (old_name )
407420 if not old_profile :
408- click .echo (f"❌ Profile '{ old_name } ' not found" )
409- click .echo ("💡 Use 'workato profiles list' to see available profiles" )
421+ if output_mode == "json" :
422+ error_msg = f"Profile '{ old_name } ' not found"
423+ output_data : dict [str , Any ] = {"status" : "error" , "error" : error_msg }
424+ click .echo (json .dumps (output_data ))
425+ else :
426+ click .echo (f"❌ Profile '{ old_name } ' not found" )
427+ click .echo ("💡 Use 'workato profiles list' to see available profiles" )
410428 return
411429
412430 # Check if new name already exists
413431 if config_manager .profile_manager .get_profile (new_name ):
414- click .echo (f"❌ Profile '{ new_name } ' already exists" )
415- click .echo ("💡 Choose a different name or delete the existing profile first" )
432+ if output_mode == "json" :
433+ error_msg = f"Profile '{ new_name } ' already exists"
434+ output_data = {"status" : "error" , "error" : error_msg }
435+ click .echo (json .dumps (output_data ))
436+ else :
437+ click .echo (f"❌ Profile '{ new_name } ' already exists" )
438+ click .echo (
439+ "💡 Choose a different name or delete the existing profile first"
440+ )
416441 return
417442
418- # Show confirmation prompt
419- if not click .confirm (f"Rename profile '{ old_name } ' to '{ new_name } '?" ):
443+ # Show confirmation prompt (skip in JSON mode or if --yes flag)
444+ if (
445+ not yes
446+ and output_mode != "json"
447+ and not click .confirm (f"Rename profile '{ old_name } ' to '{ new_name } '?" )
448+ ):
420449 click .echo ("❌ Rename cancelled" )
421450 return
422451
@@ -427,24 +456,43 @@ async def rename(
427456 try :
428457 config_manager .profile_manager .set_profile (new_name , old_profile , old_token )
429458 except ValueError as e :
430- click .echo (f"❌ Failed to create new profile: { e } " )
459+ if output_mode == "json" :
460+ output_data = {"status" : "error" , "error" : str (e )}
461+ click .echo (json .dumps (output_data ))
462+ else :
463+ click .echo (f"❌ Failed to create new profile: { e } " )
431464 return
432465
433466 # If old profile was current, set new profile as current
434467 current_profile = config_manager .profile_manager .get_current_profile_name ()
435- if current_profile == old_name :
468+ was_current = current_profile == old_name
469+ if was_current :
436470 config_manager .profile_manager .set_current_profile (new_name )
437471
438472 # Delete old profile
439473 config_manager .profile_manager .delete_profile (old_name )
440474
441475 # Update all .workatoenv files that reference the old profile
442- click .echo ("🔄 Updating project configurations..." )
476+ if output_mode == "table" :
477+ click .echo ("🔄 Updating project configurations..." )
443478 updated_files = _update_workatoenv_files (old_name , new_name )
444479
445- # Show success message
480+ # JSON output mode
481+ if output_mode == "json" :
482+ output_data = {
483+ "status" : "success" ,
484+ "old_name" : old_name ,
485+ "new_name" : new_name ,
486+ "was_current_profile" : was_current ,
487+ "updated_files" : [str (f ) for f in updated_files ],
488+ "updated_files_count" : len (updated_files ),
489+ }
490+ click .echo (json .dumps (output_data ))
491+ return
492+
493+ # Table output mode (default)
446494 click .echo ("✅ Profile renamed successfully" )
447- if current_profile == old_name :
495+ if was_current :
448496 click .echo (f"✅ Set '{ new_name } ' as the active profile" )
449497
450498 # Display updated files
0 commit comments