1+ """CLI utility helpers for tmuxp."""
12import logging
23import re
34import typing as t
@@ -18,7 +19,7 @@ def tmuxp_echo(
1819 log_level : str = "INFO" ,
1920 style_log : bool = False ,
2021) -> None :
21- """Combines logging.log and click.echo."""
22+ """Combine logging.log and click.echo."""
2223 if message is None :
2324 return
2425
@@ -36,14 +37,24 @@ def prompt(
3637 value_proc : t .Optional [t .Callable [[str ], str ]] = None ,
3738) -> str :
3839 """Return user input from command line.
40+
41+ Parameters
42+ ----------
43+ :param name: prompt text
44+ :param default: default value if no input provided.
45+
46+ Returns
47+ -------
48+ str
49+
50+ See Also
51+ --------
3952 :meth:`~prompt`, :meth:`~prompt_bool` and :meth:`prompt_choices` are from
4053 `flask-script`_. See the `flask-script license`_.
54+
4155 .. _flask-script: https://github.com/techniq/flask-script
4256 .. _flask-script license:
4357 https://github.com/techniq/flask-script/blob/master/LICENSE
44- :param name: prompt text
45- :param default: default value if no input provided.
46- :rtype: string.
4758 """
4859 _prompt = name + (default and " [%s]" % default or "" )
4960 _prompt += name .endswith ("?" ) and " " or ": "
@@ -68,12 +79,18 @@ def prompt_bool(
6879 yes_choices : t .Optional [t .Sequence [t .Any ]] = None ,
6980 no_choices : t .Optional [t .Sequence [t .Any ]] = None ,
7081) -> bool :
71- """Return user input from command line and converts to boolean value.
82+ """Return True / False by prompting user input from command line.
83+
84+ Parameters
85+ ----------
7286 :param name: prompt text
7387 :param default: default value if no input provided.
7488 :param yes_choices: default 'y', 'yes', '1', 'on', 'true', 't'
7589 :param no_choices: default 'n', 'no', '0', 'off', 'false', 'f'
76- :rtype: bool.
90+
91+ Returns
92+ -------
93+ bool
7794 """
7895 yes_choices = yes_choices or ("y" , "yes" , "1" , "on" , "true" , "t" )
7996 no_choices = no_choices or ("n" , "no" , "0" , "off" , "false" , "f" )
@@ -110,12 +127,18 @@ def prompt_choices(
110127 no_choice : t .Sequence [str ] = ("none" ,),
111128) -> t .Optional [str ]:
112129 """Return user input from command line from set of provided choices.
130+
131+ Parameters
132+ ----------
113133 :param name: prompt text
114134 :param choices: list or tuple of available choices. Choices may be
115135 single strings or (key, value) tuples.
116136 :param default: default value if no input provided.
117137 :param no_choice: acceptable list of strings for "null choice"
118- :rtype: str.
138+
139+ Returns
140+ -------
141+ str
119142 """
120143 _choices : t .List [str ] = []
121144 options : t .List [str ] = []
@@ -143,6 +166,7 @@ def prompt_choices(
143166
144167
145168def strip_ansi (value : str ) -> str :
169+ """Clear ANSI from a string value."""
146170 return _ansi_re .sub ("" , value )
147171
148172
@@ -182,6 +206,8 @@ def _interpret_color(
182206
183207
184208class UnknownStyleColor (Exception ):
209+ """Raised when encountering an unknown terminal style color."""
210+
185211 def __init__ (self , color : "CLIColour" , * args : object , ** kwargs : object ) -> None :
186212 return super ().__init__ (f"Unknown color { color !r} " , * args , ** kwargs )
187213
@@ -241,11 +267,12 @@ def style(
241267
242268
243269def unstyle (text : str ) -> str :
244- """Removes ANSI styling information from a string. Usually it's not
245- necessary to use this function as tmuxp_echo function will
270+ """Remove ANSI styling information from a string.
271+
272+ Usually it's not necessary to use this function as tmuxp_echo function will
246273 automatically remove styling if necessary.
247274
248- credit : click.
275+ Credit : click.
249276
250277 :param text: the text to remove style information from.
251278 """
0 commit comments