| 1 |
from typing import TYPE_CHECKING |
| 2 |
|
| 3 |
import click |
| 4 |
|
| 5 |
if TYPE_CHECKING: |
| 6 |
import cloup |
| 7 |
|
| 8 |
FORMATTER_TYPE_ERROR = """ |
| 9 |
since Cloup v0.8, this class relies on `cloup.HelpFormatter` to align help |
| 10 |
sections. So, you need to make sure your command class uses `cloup.HelpFormatter` |
| 11 |
as formatter class. |
| 12 |
|
| 13 |
If you have your own custom `HelpFormatter`, know that `cloup.HelpFormatter` is |
| 14 |
more easily customizable then Click's one, so consider extending it instead |
| 15 |
of extending `click.HelpFormatter`. |
| 16 |
""" |
| 17 |
|
| 18 |
|
| 19 |
def ensure_is_cloup_formatter(formatter: click.HelpFormatter) -> 'cloup.HelpFormatter': |
| 20 |
from cloup import HelpFormatter |
| 21 |
if isinstance(formatter, HelpFormatter): |
| 22 |
return formatter |
| 23 |
raise TypeError(FORMATTER_TYPE_ERROR) |
| 24 |
|
| 25 |
|
| 26 |
def unstyled_len(string: str) -> int: |
| 27 |
return len(click.unstyle(string)) |