-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
🐛 bugSomething isn't working, or a fix is proposedSomething isn't working, or a fix is proposed🙏 help wantedI can't do this alone and need contributorsI can't do this alone and need contributors
Description
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 --versionwill output a plain, uncoloured version string, while--version --no-colorwill output a coloured string.
This is highlighted by a test at:
click-extra/click_extra/tests/test_colorize.py
Lines 318 to 346 in d589907
| @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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🐛 bugSomething isn't working, or a fix is proposedSomething isn't working, or a fix is proposed🙏 help wantedI can't do this alone and need contributorsI can't do this alone and need contributors