Skip to content

Commit

Permalink
feat: allow for file based command name (0.2.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Mauroy committed Sep 21, 2023
1 parent 0d64c54 commit 245db9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <pro.julien.mauroy@gmail.com>"]
readme = "README.md"
Expand All @@ -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"


Expand Down
10 changes: 8 additions & 2 deletions src/ccl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -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():
Expand Down

0 comments on commit 245db9e

Please sign in to comment.