From 0ad314b0bf1b083168b0ab723c066812ed630dbd Mon Sep 17 00:00:00 2001 From: dormieriancitizen Date: Fri, 10 Oct 2025 16:40:40 -0400 Subject: [PATCH] Feat: package name autocompletion --- dexi/app.py | 22 +++++++++++++++++++--- dexi/commands/viewer.py | 8 ++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dexi/app.py b/dexi/app.py index 73457b0..1040b83 100644 --- a/dexi/app.py +++ b/dexi/app.py @@ -1,4 +1,5 @@ import typer +from typing_extensions import Annotated from .commands.installer import install_packages from .commands.manager import ( @@ -7,7 +8,7 @@ update_all_packages, update_package, ) -from .commands.viewer import list_packages +from .commands.viewer import autocomplete_packages, list_packages from .core.errors import Errors app = typer.Typer() @@ -31,7 +32,14 @@ def add(package: str, branch: str = "main"): @app.command() -def remove(package: str): +def remove( + package: Annotated[ + str, + typer.Argument( + help="The name of the package", autocompletion=autocomplete_packages + ), + ], +): """ Removes and uninstalls a package. @@ -46,7 +54,15 @@ def remove(package: str): @app.command() -def update(package: str | None = None): +def update( + package: Annotated[ + str, + typer.Argument( + help="The name of the package", autocompletion=autocomplete_packages + ), + ] + | None = None, +): """ Updates all packages or a specified package. diff --git a/dexi/commands/viewer.py b/dexi/commands/viewer.py index be454e6..c99bbeb 100644 --- a/dexi/commands/viewer.py +++ b/dexi/commands/viewer.py @@ -3,6 +3,14 @@ from ..core.utils import console, fetch_all_packages, fetch_pyproject, package_name +def autocomplete_packages(incomplete: str) -> list[str]: + return [ + package["git"] + for package in fetch_all_packages() + if package["git"].startswith(incomplete) + ] + + def list_packages(hide_update: bool = False): """ Displays a list of packages.