From 4a179bfa12b42b287312e50c177f2fa1790264ef Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Thu, 17 Apr 2025 16:27:08 +0000 Subject: [PATCH] bug fix, enable add alias from cli, reimporter implemented in cli --- corrlib/cli.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/corrlib/cli.py b/corrlib/cli.py index ff4f374..e703857 100644 --- a/corrlib/cli.py +++ b/corrlib/cli.py @@ -2,9 +2,10 @@ from typing import Optional import typer from corrlib import __app_name__, __version__ from .initialization import create -from .toml import import_tomls, update_project -from .find import find_record, find_project, list_projects +from .toml import import_tomls, update_project, reimport_project +from .find import find_record, list_projects from .tools import str2list +from .main import update_aliases import os app = typer.Typer() @@ -51,10 +52,32 @@ def list( elif entities == 'projects': results = list_projects(path) print("Projects:") - header = "UUID".ljust(37) + "| Names" + header = "UUID".ljust(37) + "| Aliases" print(header) for project in results: - print(project[0], "|", " | ".join(str2list(project[1]))) + if project[1] is not None: + aliases = " | ".join(str2list(project[1])) + else: + aliases = "---" + print(project[0], "|", aliases) + return + + +@app.command() +def alias_add( + path: str = typer.Option( + str('./corrlib'), + "--dataset", + "-d", + ), + uuid: str = typer.Argument(), + alias: str = typer.Argument(), +) -> None: + """ + Add an alias to a project UUID. + """ + alias_list = alias.pülit(",") + update_aliases(path, uuid, alias_list) return @@ -98,6 +121,27 @@ def importer( return +@app.command() +def reimporter( + path: str = typer.Option( + str('./corrlib'), + "--dataset", + "-d", + ), + ident: str = typer.Argument() + ) -> None: + uuid = ident.split("::")[0] + if len(ident.split("::")) > 1: + toml_file = os.path.join(path, "toml_imports", ident.split("::")[1]) + if os.path.exists(toml_file): + import_tomls(path, [toml_file], copy_files=False) + else: + raise Exception("This file is not known for this project.") + else: + reimport_project(path, uuid) + return + + @app.command() def init( path: str = typer.Option(