Render usage through Rich on option errors#14143
Conversation
| def print_usage(self, file: Any = None) -> None: | ||
| if self.usage: | ||
| console = self._create_console(file) | ||
| console.print(self.get_usage(), highlight=False) |
There was a problem hiding this comment.
The trailing newline from get_usage() is intentional, so no rstrip() here.
pip install [options] ...
<-- blank line
no such option: --updrade
|
whilst I don't disagree, I do think this should build on top of #14026 |
|
thanks @KRRT7 for the suggestion took a look. here's my concern. pip/src/pip/_internal/utils/logging.py Lines 194 to 208 in c760425 the two need different args though (file, theme, soft_wrap), so they pull in different directions. |
ichard26
left a comment
There was a problem hiding this comment.
Works and looks great, thank you!
I renamed the _create_console method to _create_console_for_help just so it's clear that this console isn't the main console used by pip. Its only purpose is for highlighting help output.
I agree this is logically separate from the linked PR.
print_usage() fell through to plain optparse and printed the Rich markup literally. override it to render through PipConsole, like print_help().
Fixes #14136
print_usage()fell through to plain optparse and printed the Rich markup literally. override it to render throughPipConsole, likeprint_help().see below:
before
after