@@ -496,6 +496,110 @@ def _rollback_interactive(ctx: typer.Context) -> None:
496496 pass
497497
498498
499+ @app .command ()
500+ def delete (
501+ ctx : typer .Context ,
502+ name : str = typer .Argument (..., help = "The logical name of the dataset to delete." ),
503+ ) -> None :
504+ """
505+ Marks a dataset for permanent deletion.
506+ This action is finalized via a Pull Request and CI/CD pipeline.
507+ """
508+ console .print (f"🗑️ Preparing deletion for [bold red]{ name } [/]." )
509+
510+ # Verify the dataset exists before proceeding
511+ if not manifest .get_dataset (name ):
512+ console .print (f"[red]Error: Dataset '{ name } ' not found.[/]" )
513+ raise typer .Exit (1 )
514+
515+ console .print (
516+ "[bold yellow]WARNING:[/] This will propose the [underline]permanent deletion[/] of the dataset and all its version history from Cloudflare R2."
517+ )
518+
519+ # Use a text prompt for strong confirmation
520+ confirmation = questionary .text (
521+ f"To confirm, please type the name of the dataset ({ name } ):"
522+ ).ask ()
523+
524+ if confirmation != name :
525+ console .print ("Confirmation failed. Deletion cancelled." )
526+ return
527+
528+ # Mark the dataset for deletion in the manifest
529+ if manifest .mark_for_deletion (name ):
530+ console .print (
531+ f"\n [bold green]✅ Dataset '{ name } ' has been marked for deletion.[/]"
532+ )
533+ console .print (
534+ "\n Next steps:\n "
535+ f" 1. [cyan]git add { settings .manifest_file } [/]\n "
536+ f' 2. [cyan]git commit -m "chore: Mark { name } for deletion"[/]\n '
537+ " 3. [cyan]git push[/]\n "
538+ " 4. Open a Pull Request to finalize the deletion."
539+ )
540+ else :
541+ # This case should be caught by the check above, but is here for safety
542+ console .print (f"[red]Error: Could not mark '{ name } ' for deletion.[/]" )
543+ raise typer .Exit (1 )
544+
545+
546+ @app .command ()
547+ def prune_versions (
548+ ctx : typer .Context ,
549+ name : str = typer .Argument (..., help = "The logical name of the dataset to prune." ),
550+ keep : int = typer .Option (
551+ ..., "--keep" , "-k" , help = "The number of most recent versions to keep."
552+ ),
553+ ) -> None :
554+ """Marks old versions of a dataset for permanent deletion."""
555+ console .print (f"🔪 Preparing to prune old versions of [cyan]{ name } [/]..." )
556+
557+ dataset = manifest .get_dataset (name )
558+ if not dataset :
559+ console .print (f"[red]Error: Dataset '{ name } ' not found.[/]" )
560+ raise typer .Exit (1 )
561+
562+ history = dataset .get ("history" , [])
563+ if len (history ) <= keep :
564+ console .print (
565+ f"✅ No action needed. Dataset has { len (history )} version(s), which is not more than the { keep } to keep."
566+ )
567+ return
568+
569+ versions_to_keep = [entry ["version" ] for entry in history [:keep ]]
570+ versions_to_delete = [entry ["version" ] for entry in history [keep :]]
571+
572+ console .print (
573+ f"You have chosen to keep the [bold green]{ keep } [/] most recent version(s):"
574+ )
575+ for v in versions_to_keep :
576+ console .print (f" - [green]{ v } [/]" )
577+
578+ console .print (
579+ f"\n The following [bold red]{ len (versions_to_delete )} [/] older version(s) will be marked for permanent deletion:"
580+ )
581+ for v in versions_to_delete :
582+ console .print (f" - [red]{ v } [/]" )
583+
584+ proceed = _ask_confirm (ctx , "\n Do you want to continue?" , default = False )
585+ if not proceed :
586+ console .print ("Pruning cancelled." )
587+ return
588+
589+ # Mark the versions for deletion in the manifest
590+ manifest .mark_versions_for_deletion (name , versions_to_delete )
591+ console .print (
592+ f"\n [bold green]✅ { len (versions_to_delete )} version(s) have been marked for deletion.[/]"
593+ )
594+ console .print (
595+ "\n Next steps:\n "
596+ f" 1. [cyan]git add { settings .manifest_file } [/]\n "
597+ f' 2. [cyan]git commit -m "chore: Prune old versions of { name } , keeping { keep } "[/]\n '
598+ " 3. [cyan]git push[/]\n "
599+ " 4. Open a Pull Request to finalize the deletion."
600+ )
601+
602+
499603@app .callback (invoke_without_command = True )
500604def main (ctx : typer .Context , no_prompt : bool = COMMON_OPTIONS ["no_prompt" ]) -> None :
501605 """
@@ -521,6 +625,8 @@ def main(ctx: typer.Context, no_prompt: bool = COMMON_OPTIONS["no_prompt"]) -> N
521625 "Prepare a dataset for release" : _prepare_interactive ,
522626 "Pull a dataset version" : _pull_interactive ,
523627 "Rollback a dataset to a previous version" : _rollback_interactive ,
628+ "Delete a dataset" : delete ,
629+ "Prune old dataset versions" : prune_versions ,
524630 "Exit" : "exit" ,
525631 }
526632
0 commit comments