Skip to content

Add @custom_version_option, freeze @version_option#3581

Open
kdeldycke wants to merge 2 commits into
pallets:mainfrom
kdeldycke:freeze-version-option
Open

Add @custom_version_option, freeze @version_option#3581
kdeldycke wants to merge 2 commits into
pallets:mainfrom
kdeldycke:freeze-version-option

Conversation

@kdeldycke

@kdeldycke kdeldycke commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

This is an attempt to address the design discussion we started in #3527 about @version_option extensibility.

What's in this PR:

  • A .. note:: admonition to point to @version_option freeze.
  • A new @custom_version_option that mirrors @help_option and @version_option and takes a callback for a custom message.

I did not take the class-based approach here, as it reminded me of the HelpOption class that I was too fast to add in #2563 (v8.1.8) then had to remove in #2832/#2840 (v8.2.0).

If I like the explicitness of the freeze admonition, I don't like the rest of the code: the naming of @custom_version_option and the apparent duplication with @version_option. But I produced this PR anyway to explore the effect of our policy and to have a concrete example to discuss.

@kdeldycke kdeldycke added this to the 8.5.0 milestone Jun 11, 2026
@kdeldycke kdeldycke added the f:parameters feature: input parameter types label Jun 11, 2026
@kdeldycke kdeldycke marked this pull request as draft June 11, 2026 05:28
@kdeldycke kdeldycke added the docs label Jun 11, 2026
@kdeldycke kdeldycke force-pushed the freeze-version-option branch 2 times, most recently from 9a54d78 to dddd703 Compare June 11, 2026 05:32
@kdeldycke kdeldycke changed the base branch from main to stable July 1, 2026 04:24
@kdeldycke kdeldycke changed the base branch from stable to main July 1, 2026 04:54
@kdeldycke kdeldycke force-pushed the freeze-version-option branch from dddd703 to 13f5085 Compare July 1, 2026 05:10
@kdeldycke kdeldycke marked this pull request as ready for review July 1, 2026 05:11
@kdeldycke kdeldycke changed the title WIP: Add @custom_version_option, freeze @version_option Add @custom_version_option, freeze @version_option Jul 1, 2026
@Rowlando13

Copy link
Copy Markdown
Member

@kdeldycke This looks good. Allows for simple customization. I would change the echo to a normal print. I think for most things we can move away from echo.

@Rowlando13

Copy link
Copy Markdown
Member

Let me know what you think about print instead of echo is this case.

@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Let me know what you think about print instead of echo is this case.

The reason we use echo instead of print is because echo is sensitive to the color state. See how it calls should_strip_ansi. And removing Colorama did not provide any simplification: we still need to adapt printing to the environment (non-tty, Ansi, CLI test runner etc).

So unless you want to reintroduce ANSI-related issues, it's better to do the reverse: always use echo unless we have a good reason to use print. :)

kdeldycke added a commit to kdeldycke/click that referenced this pull request Jul 7, 2026
@kdeldycke kdeldycke force-pushed the freeze-version-option branch from 8115d6c to 4993125 Compare July 7, 2026 13:14
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Let me know what you think about print instead of echo is this case.

I used the opportunity to grep into the code and docs and yes, we are properly using echo everywhere. I just fixed one occurence in docs/utils.md and documented the exceptional use of print to demonstrate the page usage. @Rowlando13 if you agree with these changes feel free to merge, just double-check these additions.

@kdeldycke kdeldycke force-pushed the freeze-version-option branch from 4993125 to 4453103 Compare July 7, 2026 13:24
@davidism

davidism commented Jul 7, 2026

Copy link
Copy Markdown
Member

Yeah, echo does stuff besides the weird stream stuff (which we do want to remove if possible): https://click.palletsprojects.com/en/stable/api/#click.echo. Only some of those points are (will be) still relevant. We should use it consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs f:parameters feature: input parameter types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants