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

Tweak callback evaluation order of eagerness options #137

Open
kdeldycke opened this issue Apr 11, 2022 · 0 comments
Open

Tweak callback evaluation order of eagerness options #137

kdeldycke opened this issue Apr 11, 2022 · 0 comments
Labels
🐛 bug Something isn't working, or a fix is proposed 🙏 help wanted I can't do this alone and need contributors

Comments

@kdeldycke
Copy link
Owner

Eager parameters are evaluated in the order as they were provided on the command line by the user as explained in: https://click.palletsprojects.com/en/8.0.x/advanced/#callback-evaluation-order

This means a call to:

  • --no-color --version will output a plain, uncoloured version string, while
  • --version --no-color will output a coloured string.

This is highlighted by a test at:

@skip_windows_colors
def test_color_option_precedence(invoke):
"""--no-color has an effect on --version, if placed in the right order.
Eager parameters are evaluated in the order as they were provided on the command
line by the user as expleined in:
https://click.palletsprojects.com/en/8.0.x/advanced/#callback-evaluation-order
..todo:
Maybe have the possibility to tweak CLI callback evaluation order so we can
let the user to have the NO_COLOR env set to allow for color-less --version output.
"""
@click.command()
@color_option()
@version_option(version="2.1.9")
def dummy_cli():
click.echo(Style(fg="yellow")("It works!"))
result = invoke(dummy_cli, "--no-color", "--version", "command1", color=True)
assert result.exit_code == 0
assert result.output == "dummy-cli, version 2.1.9\n"
assert not result.stderr
result = invoke(dummy_cli, "--version", "--no-color", "command1", color=True)
assert result.exit_code == 0
assert result.output == "\x1b[97mdummy-cli\x1b[0m, version \x1b[32m2.1.9\x1b[0m\n"
assert not result.stderr

It could be great to have --no-color (and its NO_COLOR env var) be respected whatever its order.

@kdeldycke kdeldycke added 🐛 bug Something isn't working, or a fix is proposed 🙏 help wanted I can't do this alone and need contributors labels Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working, or a fix is proposed 🙏 help wanted I can't do this alone and need contributors
Projects
None yet
Development

No branches or pull requests

1 participant