1
+ """CLI utility helpers for tmuxp."""
1
2
import logging
2
3
import re
3
4
import typing as t
@@ -18,7 +19,7 @@ def tmuxp_echo(
18
19
log_level : str = "INFO" ,
19
20
style_log : bool = False ,
20
21
) -> None :
21
- """Combines logging.log and click.echo."""
22
+ """Combine logging.log and click.echo."""
22
23
if message is None :
23
24
return
24
25
@@ -36,14 +37,24 @@ def prompt(
36
37
value_proc : t .Optional [t .Callable [[str ], str ]] = None ,
37
38
) -> str :
38
39
"""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
+ --------
39
52
:meth:`~prompt`, :meth:`~prompt_bool` and :meth:`prompt_choices` are from
40
53
`flask-script`_. See the `flask-script license`_.
54
+
41
55
.. _flask-script: https://github.com/techniq/flask-script
42
56
.. _flask-script license:
43
57
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.
47
58
"""
48
59
_prompt = name + (default and " [%s]" % default or "" )
49
60
_prompt += name .endswith ("?" ) and " " or ": "
@@ -68,12 +79,18 @@ def prompt_bool(
68
79
yes_choices : t .Optional [t .Sequence [t .Any ]] = None ,
69
80
no_choices : t .Optional [t .Sequence [t .Any ]] = None ,
70
81
) -> 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
+ ----------
72
86
:param name: prompt text
73
87
:param default: default value if no input provided.
74
88
:param yes_choices: default 'y', 'yes', '1', 'on', 'true', 't'
75
89
:param no_choices: default 'n', 'no', '0', 'off', 'false', 'f'
76
- :rtype: bool.
90
+
91
+ Returns
92
+ -------
93
+ bool
77
94
"""
78
95
yes_choices = yes_choices or ("y" , "yes" , "1" , "on" , "true" , "t" )
79
96
no_choices = no_choices or ("n" , "no" , "0" , "off" , "false" , "f" )
@@ -110,12 +127,18 @@ def prompt_choices(
110
127
no_choice : t .Sequence [str ] = ("none" ,),
111
128
) -> t .Optional [str ]:
112
129
"""Return user input from command line from set of provided choices.
130
+
131
+ Parameters
132
+ ----------
113
133
:param name: prompt text
114
134
:param choices: list or tuple of available choices. Choices may be
115
135
single strings or (key, value) tuples.
116
136
:param default: default value if no input provided.
117
137
:param no_choice: acceptable list of strings for "null choice"
118
- :rtype: str.
138
+
139
+ Returns
140
+ -------
141
+ str
119
142
"""
120
143
_choices : t .List [str ] = []
121
144
options : t .List [str ] = []
@@ -143,6 +166,7 @@ def prompt_choices(
143
166
144
167
145
168
def strip_ansi (value : str ) -> str :
169
+ """Clear ANSI from a string value."""
146
170
return _ansi_re .sub ("" , value )
147
171
148
172
@@ -182,6 +206,8 @@ def _interpret_color(
182
206
183
207
184
208
class UnknownStyleColor (Exception ):
209
+ """Raised when encountering an unknown terminal style color."""
210
+
185
211
def __init__ (self , color : "CLIColour" , * args : object , ** kwargs : object ) -> None :
186
212
return super ().__init__ (f"Unknown color { color !r} " , * args , ** kwargs )
187
213
@@ -241,11 +267,12 @@ def style(
241
267
242
268
243
269
def 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
246
273
automatically remove styling if necessary.
247
274
248
- credit : click.
275
+ Credit : click.
249
276
250
277
:param text: the text to remove style information from.
251
278
"""
0 commit comments