Skip to content

Commit d4746c5

Browse files
committed
Breaking: add verbose(), controlled with verbose
in `setup()` and make `debug()` controlled with `debug` in setup. This will allow writing apps that have more granular level of verbosity: * quiet (warning-fatal) * normal (info-fatal), * verbose (verbose-fatal), * debug (debug-fatal = all).
1 parent f41462c commit d4746c5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

cli_ui/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# Global variable to store configuration
2424

2525
CONFIG = {
26+
"debug": os.environ.get("DEBUG"),
2627
"verbose": os.environ.get("VERBOSE"),
2728
"quiet": False,
2829
"color": "auto",
@@ -54,6 +55,7 @@
5455

5556
def setup(
5657
*,
58+
debug: bool = False,
5759
verbose: bool = False,
5860
quiet: bool = False,
5961
color: str = "auto",
@@ -62,7 +64,8 @@ def setup(
6264
) -> None:
6365
"""Configure behavior of message functions.
6466
65-
:param verbose: Whether :func:`debug` messages should get printed
67+
:param debug: Whether :func:`debug` messages should get printed
68+
:param verbose: Whether :func:`verbose` messages should get printed
6669
:param quiet: Hide every message except :func:`warning`, :func:`error`, and
6770
:func:`fatal`
6871
:param color: Choices: 'auto', 'always', or 'never'. Whether to color output.
@@ -361,12 +364,21 @@ def info_progress(prefix: str, value: float, max_value: float) -> None:
361364
write_and_flush(sys.stdout, to_write)
362365

363366

367+
def verbose(*tokens: Token, **kwargs: Any) -> None:
368+
"""Print a verbose message.
369+
370+
Messages are shown only when ``CONFIG["verbose"]`` is true"""
371+
if not CONFIG["verbose"]:
372+
return
373+
message(*tokens, **kwargs)
374+
375+
364376
def debug(*tokens: Token, **kwargs: Any) -> None:
365377
"""Print a debug message.
366378
367-
Messages are shown only when ``CONFIG["verbose"]`` is true
379+
Messages are shown only when ``CONFIG["debug"]`` is true
368380
"""
369-
if not CONFIG["verbose"] or CONFIG["record"]:
381+
if not CONFIG["debug"] or CONFIG["record"]:
370382
return
371383
message(*tokens, **kwargs)
372384

docs/index.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Configuration
4242

4343
>>> cli_ui.debug("this will not be printed")
4444
<nothing>
45-
>>> cli_ui.setup(verbose=True)
45+
>>> cli_ui.setup(debug=True)
4646
>>> cli_ui.debug("this will be printed")
4747
this will be printed
4848

@@ -161,6 +161,13 @@ Functions below take the same arguments as the :func:`info` function
161161
>>> cli_ui.info_3("Message")
162162
* Message
163163

164+
.. autofunction:: verbose
165+
166+
::
167+
168+
>>> cli_ui.verbose("Message")
169+
<nothing>
170+
164171
.. autofunction:: debug
165172

166173
::

0 commit comments

Comments
 (0)