From 245db9e0fe3f68ae5d058fa0ee66aa4049125572 Mon Sep 17 00:00:00 2001 From: Julien Mauroy Date: Thu, 21 Sep 2023 02:10:26 +0200 Subject: [PATCH] feat: allow for file based command name (0.2.0) --- pyproject.toml | 4 ++-- src/ccl/__init__.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 292745e..b001503 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "clickloader" -version = "0.1.3" +version = "0.2.0" description = "Click Command Loader, permit to load Click command from a given folder." authors = ["Julien Mauroy "] readme = "README.md" @@ -19,7 +19,7 @@ pytest = "^7.4.0" pytest-cov = "^4.1.0" pytest-html = "^3.2.0" poethepoet = "^0.21.1" -metadeco = "^0.2.1" +metadeco = "^0.2.1" tox = "^4.6.4" diff --git a/src/ccl/__init__.py b/src/ccl/__init__.py index 04a8196..7fae7d9 100644 --- a/src/ccl/__init__.py +++ b/src/ccl/__init__.py @@ -16,11 +16,14 @@ def register_commands( group: click.Group, source: typing.Union[str, pathlib.Path], + command_name_lookup_method: typing.Literal["file", "func"] = "func", ) -> None: path = pathlib.Path(source).resolve() _log.debug(f"Started registering commands in {path.resolve()}") - commands = fetch_commands_for_group(path) + commands = fetch_commands_for_group( + path, cmd_name_method=command_name_lookup_method + ) for command in commands: _log.info( @@ -32,7 +35,7 @@ def register_commands( def fetch_commands_for_group( - source: pathlib.Path, + source: pathlib.Path, *, cmd_name_method: typing.Literal["file", "func"] = "func" ) -> typing.List[typing.Union[click.Command, click.Group]]: """Return a list of click's commands or groups. @@ -52,6 +55,9 @@ def fetch_commands_for_group( function_name = finder.find_cmd_func_name(file) command = finder.fetch_cmd_func(file, function_name, "command") + if cmd_name_method == "file": + command.name = file.stem + entities.append(command) if file.is_dir():