click-extended 1.0.1__py3-none-any.whl → 1.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
 
3
3
  from click_extended.core.decorators.argument import argument
4
4
  from click_extended.core.decorators.command import command
5
+ from click_extended.core.decorators.context import context
5
6
  from click_extended.core.decorators.env import env
6
7
  from click_extended.core.decorators.group import group
7
8
  from click_extended.core.decorators.option import option
@@ -12,6 +13,7 @@ from click_extended.core.decorators.tag import tag
12
13
  __all__ = [
13
14
  "argument",
14
15
  "command",
16
+ "context",
15
17
  "env",
16
18
  "group",
17
19
  "option",
@@ -0,0 +1,56 @@
1
+ """`ParentNode` to inject the context into the function."""
2
+
3
+ # pylint: disable=redefined-builtin
4
+ # pylint: disable=redefined-outer-name
5
+
6
+ from typing import Any
7
+
8
+ from click_extended.core.nodes.parent_node import ParentNode
9
+ from click_extended.core.other.context import Context as Ctx
10
+ from click_extended.types import Decorator
11
+
12
+
13
+ class Context(ParentNode):
14
+ """`ParentNode` to inject the context into the function."""
15
+
16
+ def load(self, context: Ctx, *args: Any, **kwargs: Any) -> Ctx:
17
+ return context
18
+
19
+
20
+ def context(
21
+ name: str = "ctx",
22
+ param: str | None = None,
23
+ help: str | None = None,
24
+ tags: str | list[str] | None = None,
25
+ **kwargs: Any,
26
+ ) -> Decorator:
27
+ """
28
+ A `ParentNode` to inject the context into the function.
29
+
30
+ Type: `ParentNode`
31
+
32
+ Args:
33
+ name (str, optional):
34
+ Internal node name (must be snake_case). Defaults
35
+ to "ctx".
36
+ param (str, optional):
37
+ The parameter name to inject into the function.
38
+ If not provided, uses `name` (or derived name).
39
+ help (str, optional):
40
+ Help text for this parameter.
41
+ tags (str | list[str], optional):
42
+ Tag(s) to associate with this parameter for grouping.
43
+ **kwargs (Any):
44
+ Additional keyword arguments.
45
+
46
+ Returns:
47
+ Callable:
48
+ A decorator function that registers the context parent node.
49
+ """
50
+ return Context.as_decorator(
51
+ name=name,
52
+ param=param,
53
+ help=help,
54
+ tags=tags,
55
+ **kwargs,
56
+ )
@@ -220,6 +220,15 @@ class Tree:
220
220
  "yes",
221
221
  )
222
222
 
223
+ parent_data: dict[str, Any] | None = None
224
+ if context.parent is not None:
225
+ parent_meta = context.parent.meta.get("click_extended", {})
226
+ parent_data = parent_meta.get("data")
227
+
228
+ data: dict[str, Any] = (
229
+ parent_data if isinstance(parent_data, dict) else {}
230
+ )
231
+
223
232
  context.meta["click_extended"] = {
224
233
  "current_scope": "root",
225
234
  "root_node": root_node,
@@ -228,7 +237,7 @@ class Tree:
228
237
  "parents": parents_dict,
229
238
  "tags": root_node.tree.tags,
230
239
  "children": children_dict,
231
- "data": {},
240
+ "data": data,
232
241
  "debug": debug,
233
242
  }
234
243
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: click_extended
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: An extension to Click with additional features like automatic async support, aliasing and a modular decorator system.
5
5
  Author-email: Marcus Fredriksson <marcus@marcusfredriksson.com>
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- click_extended/__init__.py,sha256=wTarCHBxMz59fe0vCTyq8RiN0COooJ892C0N2OuPLLQ,640
1
+ click_extended/__init__.py,sha256=mF6rVnQnG-IiMSo-hX16ZzgSv8F-F3BoAyX5PDx6x90,714
2
2
  click_extended/classes.py,sha256=SdwglQ7O5ahjYeVnaM9_hCU14BYZBv8C0ZjWQIo7A_I,837
3
3
  click_extended/errors.py,sha256=tkvAXs4oUZ8SFgX37KhYrHAlsxmOGrSFLIezCH9NDQI,13897
4
4
  click_extended/types.py,sha256=0YT4QN269H-01RVxDGSpMT_hJm8cTcONonpX4_YxJlg,238
@@ -6,6 +6,7 @@ click_extended/core/__init__.py,sha256=oTJS5M1OAwRQ57aMcWV7v2D2kHjCn8zTOpPEIRpTL
6
6
  click_extended/core/decorators/__init__.py,sha256=AxqTVsGJcCG5d60RzffSh4cqA4U_okaMl3hlObqMOy4,656
7
7
  click_extended/core/decorators/argument.py,sha256=MzkMkkayR7XeNNtbHstj1PpFnrCD-VCFAE3SnpO7OMY,7201
8
8
  click_extended/core/decorators/command.py,sha256=82rwi8PIMGgOagFoNISOQkdEebKxvS9A_RHV80shUzI,2803
9
+ click_extended/core/decorators/context.py,sha256=y_jzARNNdu2JyUhIaUFpCAurztOTsYJTX96HQ2csZs0,1546
9
10
  click_extended/core/decorators/env.py,sha256=DgbQsOZ2De-Ur5hxR8hzN3-3T16K3FLsoZHS2EsKK6c,4777
10
11
  click_extended/core/decorators/group.py,sha256=_bammCVi_7vsw7YgSUTQuQp6XFUHy7knNcOmyg6DiPc,2859
11
12
  click_extended/core/decorators/option.py,sha256=E7NzM7dNtICh9YcAvYPvJkdvuxKDNjCIFl9a8ZyhXWQ,11810
@@ -24,7 +25,7 @@ click_extended/core/nodes/validation_node.py,sha256=9X_dBbr1BB-OYRxnGsM8CoKRbKT1
24
25
  click_extended/core/other/__init__.py,sha256=xZl7jM1Wud-g2c0l-CQYSMNwsJqwNwFDLE8FGL57XjA,155
25
26
  click_extended/core/other/_click_command.py,sha256=NR7e-GyKiqyVJC8X5NjRXz5ehsYl9axVIxZCSejzUg4,1738
26
27
  click_extended/core/other/_click_group.py,sha256=BoEQoyx13n27Qy1-h_Dkaie68MlyPClIVB8cNtfPGdY,7714
27
- click_extended/core/other/_tree.py,sha256=3tRivUtKbMst_oF1uICvl7ufRotSVtISGXkBIui09l8,16081
28
+ click_extended/core/other/_tree.py,sha256=IFSA3aQ-1tHjdjLO392-RLzQrpxO9b4JsyXvjdoJZ6k,16404
28
29
  click_extended/core/other/context.py,sha256=KrXfDGoVV_xuIv6fFskF0hHtWDyRDETWoSXw24GxYs8,14619
29
30
  click_extended/decorators/__init__.py,sha256=BzOreglycbxGITsWLSB3VkN8e37F-ADYlGOWoO1aO7A,1142
30
31
  click_extended/decorators/check/__init__.py,sha256=WKwRFBWFQHxA69DcHgO23fBZfLRzM8N9uUlkrl7UCS4,2180
@@ -141,9 +142,9 @@ click_extended/utils/naming.py,sha256=kNmzOqidgZZ1dE5aMYrxpWt4VwcLuEiFunpumpfHuZ
141
142
  click_extended/utils/process.py,sha256=sU3ZCMjBgjKcDnTRLKPdQ_TAjk0AT7Q8SatagD0JyHA,9729
142
143
  click_extended/utils/selection.py,sha256=_OQC88pGPUh29boxmS5ugXEi9jZGqAG180S27PeQaj0,9875
143
144
  click_extended/utils/time.py,sha256=H5m5caIEau_1GHkiYgKL_LcTtVdw2TkFVbkqJu7A9rQ,1067
144
- click_extended-1.0.1.dist-info/licenses/AUTHORS.md,sha256=NkShPinjqtnRDQVRyVnfJuOGM56sejauE3WRoYCcbtw,132
145
- click_extended-1.0.1.dist-info/licenses/LICENSE,sha256=gjO8hzM4mFSBXFikktaXVSgmXGcre91_GPJ-E_yP56E,1075
146
- click_extended-1.0.1.dist-info/METADATA,sha256=2afilQ2XKHdUMPsZR6_-7Cv1mJW7o8UvKyeYvVS8BbY,10762
147
- click_extended-1.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
148
- click_extended-1.0.1.dist-info/top_level.txt,sha256=2G3bm6tCNv80okRm773jKTk-_z1ElY-seaozZrn_TxA,15
149
- click_extended-1.0.1.dist-info/RECORD,,
145
+ click_extended-1.0.3.dist-info/licenses/AUTHORS.md,sha256=NkShPinjqtnRDQVRyVnfJuOGM56sejauE3WRoYCcbtw,132
146
+ click_extended-1.0.3.dist-info/licenses/LICENSE,sha256=gjO8hzM4mFSBXFikktaXVSgmXGcre91_GPJ-E_yP56E,1075
147
+ click_extended-1.0.3.dist-info/METADATA,sha256=MTJuY2J-kEmVhNjLLlIeMT6-CSN9PiX0eP7kdfa5uXI,10762
148
+ click_extended-1.0.3.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
149
+ click_extended-1.0.3.dist-info/top_level.txt,sha256=2G3bm6tCNv80okRm773jKTk-_z1ElY-seaozZrn_TxA,15
150
+ click_extended-1.0.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5