Skip to content

Commit 245db9e

Browse files
author
Julien Mauroy
committed
feat: allow for file based command name (0.2.0)
1 parent 0d64c54 commit 245db9e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Diff for: pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "clickloader"
3-
version = "0.1.3"
3+
version = "0.2.0"
44
description = "Click Command Loader, permit to load Click command from a given folder."
55
authors = ["Julien Mauroy <[email protected]>"]
66
readme = "README.md"
@@ -19,7 +19,7 @@ pytest = "^7.4.0"
1919
pytest-cov = "^4.1.0"
2020
pytest-html = "^3.2.0"
2121
poethepoet = "^0.21.1"
22-
metadeco = "^0.2.1"
22+
metadeco = "^0.2.1"
2323
tox = "^4.6.4"
2424

2525

Diff for: src/ccl/__init__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
def register_commands(
1717
group: click.Group,
1818
source: typing.Union[str, pathlib.Path],
19+
command_name_lookup_method: typing.Literal["file", "func"] = "func",
1920
) -> None:
2021
path = pathlib.Path(source).resolve()
2122
_log.debug(f"Started registering commands in {path.resolve()}")
2223

23-
commands = fetch_commands_for_group(path)
24+
commands = fetch_commands_for_group(
25+
path, cmd_name_method=command_name_lookup_method
26+
)
2427

2528
for command in commands:
2629
_log.info(
@@ -32,7 +35,7 @@ def register_commands(
3235

3336

3437
def fetch_commands_for_group(
35-
source: pathlib.Path,
38+
source: pathlib.Path, *, cmd_name_method: typing.Literal["file", "func"] = "func"
3639
) -> typing.List[typing.Union[click.Command, click.Group]]:
3740
"""Return a list of click's commands or groups.
3841
@@ -52,6 +55,9 @@ def fetch_commands_for_group(
5255
function_name = finder.find_cmd_func_name(file)
5356
command = finder.fetch_cmd_func(file, function_name, "command")
5457

58+
if cmd_name_method == "file":
59+
command.name = file.stem
60+
5561
entities.append(command)
5662

5763
if file.is_dir():

0 commit comments

Comments
 (0)