From 8467cd8c4a858d04249cead3f31fccdce82f1a62 Mon Sep 17 00:00:00 2001 From: Obijuan Date: Wed, 19 Jun 2024 12:04:38 +0200 Subject: [PATCH] icm rm: initial implementation --- .vscode/launch.json | 12 ++++++++++++ icm/__main__.py | 9 +++++++++ icm/commands/cmd_rm.py | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 icm/commands/cmd_rm.py diff --git a/.vscode/launch.json b/.vscode/launch.json index b43ba60..b310fa5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,6 +53,18 @@ "justMyCode": true, "internalConsoleOptions": "neverOpen", "preLaunchTask": "Clear terminal", + }, + { + "name": "ICM rm", + "type": "debugpy", + "request": "launch", + "program": "icm-run.py", + "args": ["rm","iceK-0.1.3"], + //"console": "internalConsole", + "console": "integratedTerminal", + "justMyCode": true, + "internalConsoleOptions": "neverOpen", + "preLaunchTask": "Clear terminal", } ] } diff --git a/icm/__main__.py b/icm/__main__.py index 3ae9b2d..16d9ae1 100644 --- a/icm/__main__.py +++ b/icm/__main__.py @@ -15,6 +15,7 @@ cmd_info, cmd_install, cmd_ls, + cmd_rm, ) @@ -64,3 +65,11 @@ def ls(): """List installed collections""" cmd_ls.main() + + +@cli.command() +@click.argument("collection", nargs=1) +def rm(collection): + """Remove colections""" + + cmd_rm.main(collection) diff --git a/icm/commands/cmd_rm.py b/icm/commands/cmd_rm.py new file mode 100644 index 0000000..bcf459a --- /dev/null +++ b/icm/commands/cmd_rm.py @@ -0,0 +1,26 @@ +"""Remove installed collections""" + +import shutil +from icm.commons import commons + + +def main(name: str) -> None: + """ENTRY POINT: Remove collections + * name: Name of the collection to remove + """ + + # -- Get context information + # ctx = commons.Context() + folders = commons.Folders() + print() + + # -- Build the Path to the collection + abs_collection = folders.collections / name + + # -- Check if the collection exists, as it was type byte the user + if not abs_collection.exists(): + print(f"rm: cannot remove {name}: No such collection") + return + + # -- Remove the collection folder, along with all its files + shutil.rmtree(abs_collection)