Skip to content

Commit

Permalink
Removed apply_style from Cmd.pwarning().
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Sep 12, 2024
1 parent 673eec3 commit ea60a80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## 2.5.0 (TBD)
* Breaking Change
* `cmd2` 2.5 supports Python 3.7+ (removed support for Python 3.6)
* Bug Fixes
* Fixed issue where persistent history file was not saved upon SIGTERM and SIGHUP signals.
* Enhancements
* Removed dependency on `attrs` and replaced with [dataclasses](https://docs.python.org/3/library/dataclasses.html)
* add `allow_clipboard` initialization parameter and attribute to disable ability to
add output to the operating system clipboard
* Deletions (potentially breaking changes)
* Removed `apply_style` from `Cmd.pwarning()`.


## 2.4.3 (January 27, 2023)
Expand Down
13 changes: 3 additions & 10 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,24 +1223,17 @@ def pwarning(
msg: Any = '',
*,
end: str = '\n',
apply_style: bool = True,
paged: bool = False,
chop: bool = False,
) -> None:
"""Wraps perror, but applies ansi.style_warning by default
:param msg: object to print
:param end: string appended after the end of the message, default a newline
:param apply_style:
If True, then ansi.style_warning will be applied to the message text. Set to False in cases
where the message text already has the desired style. Defaults to True.
.. deprecated: 2.4.4
Use :meth:`~cmd2.Cmd.print_to` instead to print to stderr without style applied.
:param paged: If True, pass the output through the configured pager.
:param chop: If paged is True, True to truncate long lines or False to wrap long lines.
"""
self.print_to(sys.stderr, msg, end=end, style=ansi.style_warning if apply_style else None, paged=paged, chop=chop)
self.print_to(sys.stderr, msg, end=end, style=ansi.style_warning, paged=paged, chop=chop)

def pfailure(
self,
Expand Down Expand Up @@ -2437,7 +2430,7 @@ def sigint_handler(self, signum: int, _: FrameType) -> None:
if raise_interrupt:
self._raise_keyboard_interrupt()

def sigterm_handler(self, signum: int, _: FrameType) -> None:
def sigterm_handler(self, signum: int, _: FrameType) -> None: # pragma: no cover
"""
Signal handler for SIGTERMs which are sent to politely ask this app to terminate.
Expand All @@ -2449,7 +2442,7 @@ def sigterm_handler(self, signum: int, _: FrameType) -> None:
# Gracefully exit so the persistent history file will be written.
sys.exit(self.exit_code)

def sighup_handler(self, signum: int, _: FrameType) -> None:
def sighup_handler(self, signum: int, _: FrameType) -> None: # pragma: no cover
"""
Signal handler for SIGHUPs which are sent when the terminal is closed.
Expand Down
18 changes: 0 additions & 18 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2316,24 +2316,6 @@ def test_perror_no_style(base_app, capsys):
assert err == msg + end


@with_ansi_style(ansi.AllowStyle.ALWAYS)
def test_pwarning_style(base_app, capsys):
msg = 'testing...'
end = '\n'
base_app.pwarning(msg)
out, err = capsys.readouterr()
assert err == ansi.style_warning(msg) + end


@with_ansi_style(ansi.AllowStyle.ALWAYS)
def test_pwarning_no_style(base_app, capsys):
msg = 'testing...'
end = '\n'
base_app.pwarning(msg, apply_style=False)
out, err = capsys.readouterr()
assert err == msg + end


@with_ansi_style(ansi.AllowStyle.ALWAYS)
def test_pexcept_style(base_app, capsys):
msg = Exception('testing...')
Expand Down

0 comments on commit ea60a80

Please sign in to comment.