Skip to content

Commit

Permalink
cli(utils): Note pydocstyle updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Dec 21, 2023
1 parent 179f1ec commit 635c245
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/tmuxp/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CLI utility helpers for tmuxp."""
import logging
import re
import typing as t
Expand All @@ -18,7 +19,7 @@ def tmuxp_echo(
log_level: str = "INFO",
style_log: bool = False,
) -> None:
"""Combines logging.log and click.echo."""
"""Combine logging.log and click.echo."""
if message is None:
return

Expand All @@ -36,14 +37,24 @@ def prompt(
value_proc: t.Optional[t.Callable[[str], str]] = None,
) -> str:
"""Return user input from command line.
Parameters
----------
:param name: prompt text
:param default: default value if no input provided.
Returns
-------
str
See Also
--------
:meth:`~prompt`, :meth:`~prompt_bool` and :meth:`prompt_choices` are from
`flask-script`_. See the `flask-script license`_.
.. _flask-script: https://github.com/techniq/flask-script
.. _flask-script license:
https://github.com/techniq/flask-script/blob/master/LICENSE
:param name: prompt text
:param default: default value if no input provided.
:rtype: string.
"""
_prompt = name + (default and " [%s]" % default or "")
_prompt += name.endswith("?") and " " or ": "
Expand All @@ -68,12 +79,18 @@ def prompt_bool(
yes_choices: t.Optional[t.Sequence[t.Any]] = None,
no_choices: t.Optional[t.Sequence[t.Any]] = None,
) -> bool:
"""Return user input from command line and converts to boolean value.
"""Return True / False by prompting user input from command line.
Parameters
----------
:param name: prompt text
:param default: default value if no input provided.
:param yes_choices: default 'y', 'yes', '1', 'on', 'true', 't'
:param no_choices: default 'n', 'no', '0', 'off', 'false', 'f'
:rtype: bool.
Returns
-------
bool
"""
yes_choices = yes_choices or ("y", "yes", "1", "on", "true", "t")
no_choices = no_choices or ("n", "no", "0", "off", "false", "f")
Expand Down Expand Up @@ -110,12 +127,18 @@ def prompt_choices(
no_choice: t.Sequence[str] = ("none",),
) -> t.Optional[str]:
"""Return user input from command line from set of provided choices.
Parameters
----------
:param name: prompt text
:param choices: list or tuple of available choices. Choices may be
single strings or (key, value) tuples.
:param default: default value if no input provided.
:param no_choice: acceptable list of strings for "null choice"
:rtype: str.
Returns
-------
str
"""
_choices: t.List[str] = []
options: t.List[str] = []
Expand Down Expand Up @@ -143,6 +166,7 @@ def prompt_choices(


def strip_ansi(value: str) -> str:
"""Clear ANSI from a string value."""
return _ansi_re.sub("", value)


Expand Down Expand Up @@ -182,6 +206,8 @@ def _interpret_color(


class UnknownStyleColor(Exception):
"""Raised when encountering an unknown terminal style color."""

def __init__(self, color: "CLIColour", *args: object, **kwargs: object) -> None:
return super().__init__(f"Unknown color {color!r}", *args, **kwargs)

Expand Down Expand Up @@ -241,11 +267,12 @@ def style(


def unstyle(text: str) -> str:
"""Removes ANSI styling information from a string. Usually it's not
necessary to use this function as tmuxp_echo function will
"""Remove ANSI styling information from a string.
Usually it's not necessary to use this function as tmuxp_echo function will
automatically remove styling if necessary.
credit: click.
Credit: click.
:param text: the text to remove style information from.
"""
Expand Down

0 comments on commit 635c245

Please sign in to comment.