From f4ed54f64ef58f6327c8e697ed1f85311395f61f Mon Sep 17 00:00:00 2001 From: Salar Nosrati-Ershad Date: Tue, 27 Feb 2024 21:04:08 +0330 Subject: [PATCH] add python_version to version_option available message formats --- src/click/decorators.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/click/decorators.py b/src/click/decorators.py index 4d11478f1..2d863fd27 100644 --- a/src/click/decorators.py +++ b/src/click/decorators.py @@ -454,8 +454,8 @@ def version_option( :param prog_name: The name of the CLI to show in the message. If not provided, it will be detected from the command. :param message: The message to show. The values ``%(prog)s``, - ``%(package)s``, and ``%(version)s`` are available. Defaults to - ``"%(prog)s, version %(version)s"``. + ``%(package)s``, ``%(version)s`` and ``%(python_version)`` are + available. Defaults to ``"%(prog)s, version %(version)s"``. :param kwargs: Extra arguments are passed to :func:`option`. :raise RuntimeError: ``version`` could not be detected. @@ -514,9 +514,17 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None: raise RuntimeError( f"Could not determine the version for {package_name!r} automatically." ) + import platform + python_version = platform.python_version() echo( - message % {"prog": prog_name, "package": package_name, "version": version}, + message + % { + "prog": prog_name, + "package": package_name, + "version": version, + "python_version": python_version, + }, color=ctx.color, ) ctx.exit()