Skip to content

Breaking: add verbose(), controlled with verbose #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cli_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Global variable to store configuration

CONFIG = {
"debug": os.environ.get("DEBUG"),
"verbose": os.environ.get("VERBOSE"),
"quiet": False,
"color": "auto",
Expand Down Expand Up @@ -54,6 +55,7 @@

def setup(
*,
debug: bool = False,
verbose: bool = False,
quiet: bool = False,
color: str = "auto",
Expand All @@ -62,7 +64,8 @@ def setup(
) -> None:
"""Configure behavior of message functions.

:param verbose: Whether :func:`debug` messages should get printed
:param debug: Whether :func:`debug` messages should get printed
:param verbose: Whether :func:`verbose` messages should get printed
:param quiet: Hide every message except :func:`warning`, :func:`error`, and
:func:`fatal`
:param color: Choices: 'auto', 'always', or 'never'. Whether to color output.
Expand Down Expand Up @@ -361,12 +364,21 @@ def info_progress(prefix: str, value: float, max_value: float) -> None:
write_and_flush(sys.stdout, to_write)


def verbose(*tokens: Token, **kwargs: Any) -> None:
"""Print a verbose message.

Messages are shown only when ``CONFIG["verbose"]`` is true"""
if not CONFIG["verbose"]:
return
message(*tokens, **kwargs)


def debug(*tokens: Token, **kwargs: Any) -> None:
"""Print a debug message.

Messages are shown only when ``CONFIG["verbose"]`` is true
Messages are shown only when ``CONFIG["debug"]`` is true
"""
if not CONFIG["verbose"] or CONFIG["record"]:
if not CONFIG["debug"] or CONFIG["record"]:
return
message(*tokens, **kwargs)

Expand Down
9 changes: 8 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Configuration

>>> cli_ui.debug("this will not be printed")
<nothing>
>>> cli_ui.setup(verbose=True)
>>> cli_ui.setup(debug=True)
>>> cli_ui.debug("this will be printed")
this will be printed

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

.. autofunction:: verbose

::

>>> cli_ui.verbose("Message")
<nothing>

.. autofunction:: debug

::
Expand Down