Skip to content

Commit b8a0edb

Browse files
kmvanbrunttleonhardt
authored andcommitted
Simplified docstrings for the print functions which call print_to().
1 parent fd6011a commit b8a0edb

File tree

2 files changed

+24
-86
lines changed

2 files changed

+24
-86
lines changed

cmd2/cmd2.py

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,19 +1260,7 @@ def poutput(
12601260
) -> None:
12611261
"""Print objects to self.stdout.
12621262
1263-
:param objects: objects to print
1264-
:param sep: string to write between print data. Defaults to " ".
1265-
:param end: string to write at end of print data. Defaults to a newline.
1266-
:param style: optional style to apply to output
1267-
:param soft_wrap: Enable soft wrap mode. If True, text lines will not be automatically word-wrapped to fit the
1268-
terminal width; instead, any text that doesn't fit will run onto the following line(s),
1269-
similar to the built-in print() function. Set to False to enable automatic word-wrapping.
1270-
If None (the default for this parameter), the output will default to no word-wrapping, as
1271-
configured by the Cmd2GeneralConsole.
1272-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1273-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1274-
method and still call `super()` without encountering unexpected keyword argument errors.
1275-
These arguments are not passed to Rich's Console.print().
1263+
For details on the parameters, refer to the `print_to` method documentation.
12761264
"""
12771265
self.print_to(
12781266
self.stdout,
@@ -1296,19 +1284,9 @@ def perror(
12961284
) -> None:
12971285
"""Print objects to sys.stderr.
12981286
1299-
:param objects: objects to print
1300-
:param sep: string to write between print data. Defaults to " ".
1301-
:param end: string to write at end of print data. Defaults to a newline.
13021287
:param style: optional style to apply to output. Defaults to Cmd2Style.ERROR.
1303-
:param soft_wrap: Enable soft wrap mode. If True, text lines will not be automatically word-wrapped to fit the
1304-
terminal width; instead, any text that doesn't fit will run onto the following line(s),
1305-
similar to the built-in print() function. Set to False to enable automatic word-wrapping.
1306-
If None (the default for this parameter), the output will default to no word-wrapping, as
1307-
configured by the Cmd2GeneralConsole.
1308-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1309-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1310-
method and still call `super()` without encountering unexpected keyword argument errors.
1311-
These arguments are not passed to Rich's Console.print().
1288+
1289+
For details on the other parameters, refer to the `print_to` method documentation.
13121290
"""
13131291
self.print_to(
13141292
sys.stderr,
@@ -1331,18 +1309,7 @@ def psuccess(
13311309
) -> None:
13321310
"""Wrap poutput, but apply Cmd2Style.SUCCESS.
13331311
1334-
:param objects: objects to print
1335-
:param sep: string to write between print data. Defaults to " ".
1336-
:param end: string to write at end of print data. Defaults to a newline.
1337-
:param soft_wrap: Enable soft wrap mode. If True, text lines will not be automatically word-wrapped to fit the
1338-
terminal width; instead, any text that doesn't fit will run onto the following line(s),
1339-
similar to the built-in print() function. Set to False to enable automatic word-wrapping.
1340-
If None (the default for this parameter), the output will default to no word-wrapping, as
1341-
configured by the Cmd2GeneralConsole.
1342-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1343-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1344-
method and still call `super()` without encountering unexpected keyword argument errors.
1345-
These arguments are not passed to Rich's Console.print().
1312+
For details on the parameters, refer to the `print_to` method documentation.
13461313
"""
13471314
self.poutput(
13481315
*objects,
@@ -1364,18 +1331,7 @@ def pwarning(
13641331
) -> None:
13651332
"""Wrap perror, but apply Cmd2Style.WARNING.
13661333
1367-
:param objects: objects to print
1368-
:param sep: string to write between print data. Defaults to " ".
1369-
:param end: string to write at end of print data. Defaults to a newline.
1370-
:param soft_wrap: Enable soft wrap mode. If True, text lines will not be automatically word-wrapped to fit the
1371-
terminal width; instead, any text that doesn't fit will run onto the following line(s),
1372-
similar to the built-in print() function. Set to False to enable automatic word-wrapping.
1373-
If None (the default for this parameter), the output will default to no word-wrapping, as
1374-
configured by the Cmd2GeneralConsole.
1375-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1376-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1377-
method and still call `super()` without encountering unexpected keyword argument errors.
1378-
These arguments are not passed to Rich's Console.print().
1334+
For details on the parameters, refer to the `print_to` method documentation.
13791335
"""
13801336
self.perror(
13811337
*objects,
@@ -1393,20 +1349,19 @@ def pexcept(
13931349
rich_print_kwargs: RichPrintKwargs | None = None,
13941350
**kwargs: Any, # noqa: ARG002
13951351
) -> None:
1396-
"""Print exception to sys.stderr. If debug is true, print exception traceback if one exists.
1352+
"""Print an exception to sys.stderr.
13971353
1398-
:param exception: the exception to print.
1399-
:param end: string to write at end of print data. Defaults to a newline.
1400-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1401-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1402-
method and still call `super()` without encountering unexpected keyword argument errors.
1403-
These arguments are not passed to Rich's Console.print().
1354+
If `debug` is true, a full exception traceback is also printed, if one exists.
1355+
1356+
:param exception: the exception to be printed.
1357+
1358+
For details on the other parameters, refer to the `print_to` method documentation.
14041359
"""
14051360
final_msg = Text()
14061361

14071362
if self.debug and sys.exc_info() != (None, None, None):
14081363
console = Cmd2GeneralConsole(sys.stderr)
1409-
console.print_exception(word_wrap=True)
1364+
console.print_exception(word_wrap=True, max_frames=0)
14101365
else:
14111366
final_msg += f"EXCEPTION of type '{type(exception).__name__}' occurred with message: {exception}"
14121367

@@ -1431,23 +1386,12 @@ def pfeedback(
14311386
rich_print_kwargs: RichPrintKwargs | None = None,
14321387
**kwargs: Any, # noqa: ARG002
14331388
) -> None:
1434-
"""For printing nonessential feedback. Can be silenced with `quiet`.
1389+
"""Print nonessential feedback.
14351390
1436-
Inclusion in redirected output is controlled by `feedback_to_output`.
1391+
The output can be silenced with the `quiet` setting and its inclusion in redirected output
1392+
is controlled by the `feedback_to_output` setting.
14371393
1438-
:param objects: objects to print
1439-
:param sep: string to write between print data. Defaults to " ".
1440-
:param end: string to write at end of print data. Defaults to a newline.
1441-
:param style: optional style to apply to output
1442-
:param soft_wrap: Enable soft wrap mode. If True, text lines will not be automatically word-wrapped to fit the
1443-
terminal width; instead, any text that doesn't fit will run onto the following line(s),
1444-
similar to the built-in print() function. Set to False to enable automatic word-wrapping.
1445-
If None (the default for this parameter), the output will default to no word-wrapping, as
1446-
configured by the Cmd2GeneralConsole.
1447-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1448-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1449-
method and still call `super()` without encountering unexpected keyword argument errors.
1450-
These arguments are not passed to Rich's Console.print().
1394+
For details on the parameters, refer to the `print_to` method documentation.
14511395
"""
14521396
if not self.quiet:
14531397
if self.feedback_to_output:
@@ -1480,15 +1424,12 @@ def ppaged(
14801424
rich_print_kwargs: RichPrintKwargs | None = None,
14811425
**kwargs: Any, # noqa: ARG002
14821426
) -> None:
1483-
"""Print output using a pager if it would go off screen and stdout isn't currently being redirected.
1427+
"""Print output using a pager.
14841428
1485-
Never uses a pager inside a script (Python or text) or when output is being redirected or piped or when
1486-
stdout or stdin are not a fully functional terminal.
1429+
A pager is used when the terminal is interactive and may exit immediately if the output
1430+
fits on the screen. A pager is not used inside a script (Python or text) or when output is
1431+
redirected or piped, and in these cases, output is sent to `poutput`.
14871432
1488-
:param objects: objects to print
1489-
:param sep: string to write between print data. Defaults to " ".
1490-
:param end: string to write at end of print data. Defaults to a newline.
1491-
:param style: optional style to apply to output
14921433
:param chop: True -> causes lines longer than the screen width to be chopped (truncated) rather than wrapped
14931434
- truncated text is still accessible by scrolling with the right & left arrow keys
14941435
- chopping is ideal for displaying wide tabular data as is done in utilities like pgcli
@@ -1500,13 +1441,12 @@ def ppaged(
15001441
similar to the built-in print() function. Set to False to enable automatic word-wrapping.
15011442
If None (the default for this parameter), the output will default to no word-wrapping, as
15021443
configured by the Cmd2GeneralConsole.
1444+
15031445
Note: If chop is True and a pager is used, soft_wrap is automatically set to True.
1504-
:param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console.print().
1505-
:param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1506-
method and still call `super()` without encountering unexpected keyword argument errors.
1507-
These arguments are not passed to Rich's Console.print().
1446+
1447+
For details on the other parameters, refer to the `print_to` method documentation.
15081448
"""
1509-
# Detect if we are running within a fully functional terminal.
1449+
# Detect if we are running within an interactive terminal.
15101450
# Don't try to use the pager when being run by a continuous integration system like Jenkins + pexpect.
15111451
functional_terminal = (
15121452
self.stdin.isatty()

cmd2/styles.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Cmd2Style(StrEnum):
3434
EXAMPLE = "cmd2.example" # Command line examples in help text
3535
HELP_HEADER = "cmd2.help.header" # Help table header text
3636
HELP_LEADER = "cmd2.help.leader" # Text right before the help tables are listed
37-
RULE_LINE = "rule.line" # Rich style for horizontal rules
3837
SUCCESS = "cmd2.success" # Success text (used by psuccess())
3938
TABLE_BORDER = "cmd2.table_border" # Applied to cmd2's table borders
4039
WARNING = "cmd2.warning" # Warning text (used by pwarning())
@@ -46,7 +45,6 @@ class Cmd2Style(StrEnum):
4645
Cmd2Style.EXAMPLE: Style(color=Color.CYAN, bold=True),
4746
Cmd2Style.HELP_HEADER: Style(color=Color.BRIGHT_GREEN, bold=True),
4847
Cmd2Style.HELP_LEADER: Style(color=Color.CYAN, bold=True),
49-
Cmd2Style.RULE_LINE: Style(color=Color.BRIGHT_GREEN),
5048
Cmd2Style.SUCCESS: Style(color=Color.GREEN),
5149
Cmd2Style.TABLE_BORDER: Style(color=Color.BRIGHT_GREEN),
5250
Cmd2Style.WARNING: Style(color=Color.BRIGHT_YELLOW),

0 commit comments

Comments
 (0)