]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/click/globals.py
2 from threading
import local
5 import typing_extensions
as te
6 from .core
import Context
12 def get_current_context(silent
: "te.Literal[False]" = False) -> "Context":
17 def get_current_context(silent
: bool = ...) -> t
.Optional
["Context"]:
21 def get_current_context(silent
: bool = False) -> t
.Optional
["Context"]:
22 """Returns the current click context. This can be used as a way to
23 access the current context object from anywhere. This is a more implicit
24 alternative to the :func:`pass_context` decorator. This function is
25 primarily useful for helpers such as :func:`echo` which might be
26 interested in changing its behavior based on the current context.
28 To push the current context, :meth:`Context.scope` can be used.
32 :param silent: if set to `True` the return value is `None` if no context
33 is available. The default behavior is to raise a
37 return t
.cast("Context", _local
.stack
[-1])
38 except (AttributeError, IndexError) as e
:
40 raise RuntimeError("There is no active click context.") from e
45 def push_context(ctx
: "Context") -> None:
46 """Pushes a new context to the current stack."""
47 _local
.__dict
__.setdefault("stack", []).append(ctx
)
50 def pop_context() -> None:
51 """Removes the top level from the stack."""
55 def resolve_color_default(color
: t
.Optional
[bool] = None) -> t
.Optional
[bool]:
56 """Internal helper to get the default value of the color flag. If a
57 value is passed it's returned unchanged, otherwise it's looked up from
63 ctx
= get_current_context(silent
=True)