File: _util.py

package info (click to toggle)
python-cloup 3.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 936 kB
  • sloc: python: 5,371; makefile: 120
file content (27 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import TYPE_CHECKING

import click

if TYPE_CHECKING:
    import cloup

FORMATTER_TYPE_ERROR = """
since Cloup v0.8, this class relies on `cloup.HelpFormatter` to align help
sections. So, you need to make sure your command class uses `cloup.HelpFormatter`
as formatter class.

If you have your own custom `HelpFormatter`, know that `cloup.HelpFormatter` is
more easily customizable then Click's one, so consider extending it instead
of extending `click.HelpFormatter`.
"""


def ensure_is_cloup_formatter(formatter: click.HelpFormatter) -> 'cloup.HelpFormatter':
    from cloup import HelpFormatter
    if isinstance(formatter, HelpFormatter):
        return formatter
    raise TypeError(FORMATTER_TYPE_ERROR)


def unstyled_len(string: str) -> int:
    return len(click.unstyle(string))