@@ -54,10 +54,11 @@ def __init__(self, *args, **kwargs) -> None: # type: ignore
5454 if Flags .v08 .is_enabled ():
5555 self .command ("build" )(self .build_v2 )
5656 self .command ("deploy" )(self .deploy_v2 )
57+ self .command ("clean" )(self .clean_v2 )
5758 else :
5859 self .command ()(self .build )
5960 self .command ()(self .deploy )
60- self .command ()(self .clean )
61+ self .command ()(self .clean )
6162
6263 def common (
6364 self ,
@@ -418,6 +419,21 @@ def deploy_v2(
418419 " and provide a report of the changes that would be made." ,
419420 ),
420421 ] = False ,
422+ drop : Annotated [
423+ bool ,
424+ typer .Option (
425+ "--drop" ,
426+ "-d" ,
427+ help = "Whether to drop existing configurations, drop per resource if present." ,
428+ ),
429+ ] = False ,
430+ drop_data : Annotated [
431+ bool ,
432+ typer .Option (
433+ "--drop-data" ,
434+ help = "Only applicable if drop is set. Whether to drop configurations that contains data, such as data model containers and spaces. Use with caution." ,
435+ ),
436+ ] = False ,
421437 include : Annotated [
422438 list [str ] | None ,
423439 typer .Option (
@@ -468,6 +484,8 @@ def deploy_v2(
468484 options = DeployOptions (
469485 cdf_project = cdf_project ,
470486 dry_run = dry_run ,
487+ drop = drop ,
488+ drop_data = drop_data ,
471489 include = include ,
472490 force_update = force_update ,
473491 verbose = verbose ,
@@ -544,3 +562,84 @@ def clean(
544562 all_modules = False ,
545563 )
546564 )
565+
566+ def clean_v2 (
567+ self ,
568+ ctx : typer .Context ,
569+ build_dir : Annotated [
570+ Path ,
571+ typer .Argument (
572+ help = "Where to find the resource configurations to clean." ,
573+ allow_dash = True ,
574+ ),
575+ ] = Path ("./build" ),
576+ dry_run : Annotated [
577+ bool ,
578+ typer .Option (
579+ "--dry-run" ,
580+ "-r" ,
581+ help = "Whether to do a dry-run, do dry-run if present" ,
582+ ),
583+ ] = False ,
584+ drop_data : Annotated [
585+ bool ,
586+ typer .Option (
587+ "--drop-data" ,
588+ help = "Whether to drop configurations that contains data, such as data model containers and spaces. Use with caution." ,
589+ ),
590+ ] = False ,
591+ include : Annotated [
592+ list [str ] | None ,
593+ typer .Option (
594+ "--include" ,
595+ help = f"Specify which resource types to clean, supported types: { AVAILABLE_DATA_TYPES } " ,
596+ ),
597+ ] = None ,
598+ clean_dir : Annotated [
599+ Path ,
600+ typer .Option (
601+ "--log-dir" ,
602+ "-l" ,
603+ help = "Path to the directory where logs will be stored. If the directory does not exist, it will be created." ,
604+ ),
605+ ] = Path (f"clean_logs_{ TODAY !s} " ),
606+ cdf_project : Annotated [
607+ str | None ,
608+ typer .Option (
609+ "--cdf-project" ,
610+ help = "The CDF Project you are cleaning. This is used to verify against the credentials you have set."
611+ "If it is not passed, Toolkit will validate against the CDF project the configurations were built"
612+ "for, and if that is missing you will be prompted for it." ,
613+ ),
614+ ] = None ,
615+ verbose : Annotated [
616+ bool ,
617+ typer .Option (
618+ "--verbose" ,
619+ "-v" ,
620+ help = "Turn on to get more verbose output when running the command" ,
621+ ),
622+ ] = False ,
623+ ) -> None :
624+ """Cleans the resources in the build directory from the CDF project."""
625+ # Override cluster and project from the options/env variables
626+ env_vars = EnvironmentVariables .create_from_environment ()
627+ cmd = DeployV2Command (print_warning = True , client = env_vars .get_client ())
628+ cmd .run (
629+ lambda : cmd .deploy (
630+ env_vars = env_vars ,
631+ user_build_dir = build_dir ,
632+ options = DeployOptions (
633+ operation = "clean" ,
634+ cdf_project = cdf_project ,
635+ drop = True ,
636+ drop_data = drop_data ,
637+ dry_run = dry_run ,
638+ include = include ,
639+ force_update = False ,
640+ verbose = verbose ,
641+ environment_variables = env_vars .dump (),
642+ deployment_dir = clean_dir ,
643+ ),
644+ )
645+ )
0 commit comments