Skip to content

Commit 47bbf55

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 47bbf55

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cli_ui/__init__.py

+15-3
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

0 commit comments

Comments
 (0)