Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: add python_version to version_option available message formats #2681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/click/decorators.py
Expand Up @@ -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.

Expand Down Expand Up @@ -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()
Expand Down