diff --git a/merlin/db_scripts/db_commands.py b/merlin/db_scripts/db_commands.py index 2184d849..dcce07dd 100644 --- a/merlin/db_scripts/db_commands.py +++ b/merlin/db_scripts/db_commands.py @@ -85,7 +85,7 @@ def database_delete(args: Namespace): if args.delete_type == "study": merlin_db.delete_study(args.study, remove_associated_runs=(not args.keep_associated_runs)) elif args.delete_type == "all-studies": - merlin_db.delete_all_studies() + merlin_db.delete_all_studies(remove_associated_runs=(not args.keep_associated_runs)) elif args.delete_type == "run": merlin_db.delete_run(args.run) elif args.delete_type == "all-runs": diff --git a/merlin/db_scripts/db_study.py b/merlin/db_scripts/db_study.py index e94ebdcf..133f261f 100644 --- a/merlin/db_scripts/db_study.py +++ b/merlin/db_scripts/db_study.py @@ -94,11 +94,17 @@ def __str__(self) -> str: A human-readable string representation of the `DatabaseStudy` instance. """ study_id = self.get_id() + runs_str = "Runs:\n" + for run in self.get_all_runs(): + runs_str += ( + f" - ID: {run.get_id()}\n" + f" Workspace: {run.get_workspace()}\n" + ) return ( f"Study with ID {study_id}\n" f"------------{'-' * len(study_id)}\n" f"Name: {self.get_name()}\n" - f"Runs: {self.get_all_runs()}\n" + f"{runs_str}" f"Additional Data: {self.get_additional_data()}\n\n" ) diff --git a/merlin/main.py b/merlin/main.py index 89f69137..76d9407f 100644 --- a/merlin/main.py +++ b/merlin/main.py @@ -879,11 +879,12 @@ def setup_argparse() -> None: # pylint: disable=R0915 # Add subcommands for delete delete_subcommands = db_delete.add_subparsers(dest="delete_type", required=True) + # TODO enable support for deletion of study by name, ID, or passing in spec file # Subcommand: delete study delete_study = ( - delete_subcommands.add_parser( # TODO perhaps this should just take in a spec file instead of the study name? + delete_subcommands.add_parser( "study", - help="Delete a specific study by name.", # TODO add option to delete by ID here as well + help="Delete a specific study by name.", formatter_class=ArgumentDefaultsHelpFormatter, ) ) @@ -899,10 +900,11 @@ def setup_argparse() -> None: # pylint: disable=R0915 help="Keep runs associated with the study.", ) + # TODO enable support for deletion of run by workspace or ID # Subcommand: delete run delete_run = delete_subcommands.add_parser( "run", - help="Delete a specific run by ID.", # TODO add option to delete by workspace here as well + help="Delete a specific run by ID.", formatter_class=ArgumentDefaultsHelpFormatter, ) delete_run.add_argument( @@ -910,7 +912,7 @@ def setup_argparse() -> None: # pylint: disable=R0915 type=str, help="The ID of the run to delete.", ) - # TODO implement the below option + # TODO implement the below option; this removes the output workspace from file system # delete_run.add_argument( # "--delete-workspace", # action="store_true", @@ -918,11 +920,17 @@ def setup_argparse() -> None: # pylint: disable=R0915 # ) # Subcommand: delete all-studies - delete_subcommands.add_parser( + delete_all_studies = delete_subcommands.add_parser( "all-studies", help="Delete all studies from the database.", formatter_class=ArgumentDefaultsHelpFormatter, ) + delete_all_studies.add_argument( + "-k", + "--keep-associated-runs", + action="store_true", + help="Keep runs associated with the studies.", + ) # Subcommand: delete all-runs delete_subcommands.add_parser( @@ -949,9 +957,11 @@ def setup_argparse() -> None: # pylint: disable=R0915 # Add subcommands for get get_subcommands = db_get.add_subparsers(dest="get_type", required=True) - get_study = get_subcommands.add_parser( # TODO perhaps this should just take in a spec file instead of the study name? + # TODO enable support for retrieval of study by name, ID, or passing in spec file + # Subcommand: get study + get_study = get_subcommands.add_parser( "study", - help="Get a specific study by name.", # TODO add option to get by ID here as well + help="Get a specific study by name.", formatter_class=ArgumentDefaultsHelpFormatter, ) get_study.add_argument( @@ -960,10 +970,11 @@ def setup_argparse() -> None: # pylint: disable=R0915 help="The name of the study to get.", ) + # TODO enable support for retrieval of run by workspace or ID # Subcommand: get run get_run = get_subcommands.add_parser( "run", - help="Get a specific run by ID.", # TODO add option to get by workspace here as well + help="Get a specific run by ID.", formatter_class=ArgumentDefaultsHelpFormatter, ) get_run.add_argument(