Skip to content

Commit 837a3d4

Browse files
committed
Even more code cleanup.
1 parent 0492c6d commit 837a3d4

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

cmd2/cmd2.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,56 +4190,57 @@ def _print_documented_command_topics(self, header: str, cmds: list[str], verbose
41904190

41914191
if not verbose:
41924192
self.print_topics(header, cmds, 15, 80)
4193-
else:
4194-
category_grid = Table.grid()
4195-
category_grid.add_row(header, style=Cmd2Style.HELP_HEADER)
4196-
category_grid.add_row(Rule(characters=self.ruler))
4197-
topics_table = Table(
4198-
Column("Name", no_wrap=True),
4199-
Column("Description", overflow="fold"),
4200-
box=SIMPLE_HEAD,
4201-
border_style=Cmd2Style.RULE_LINE,
4202-
show_edge=False,
4203-
)
4193+
return
42044194

4205-
# Try to get the documentation string for each command
4206-
topics = self.get_help_topics()
4207-
for command in cmds:
4208-
if (cmd_func := self.cmd_func(command)) is None:
4209-
continue
4195+
category_grid = Table.grid()
4196+
category_grid.add_row(header, style=Cmd2Style.HELP_HEADER)
4197+
category_grid.add_row(Rule(characters=self.ruler))
4198+
topics_table = Table(
4199+
Column("Name", no_wrap=True),
4200+
Column("Description", overflow="fold"),
4201+
box=SIMPLE_HEAD,
4202+
border_style=Cmd2Style.RULE_LINE,
4203+
show_edge=False,
4204+
)
42104205

4211-
doc: str | None
4206+
# Try to get the documentation string for each command
4207+
topics = self.get_help_topics()
4208+
for command in cmds:
4209+
if (cmd_func := self.cmd_func(command)) is None:
4210+
continue
42124211

4213-
# Non-argparse commands can have help_functions for their documentation
4214-
if command in topics:
4215-
help_func = getattr(self, constants.HELP_FUNC_PREFIX + command)
4216-
result = io.StringIO()
4217-
4218-
# try to redirect system stdout
4219-
with contextlib.redirect_stdout(result):
4220-
# save our internal stdout
4221-
stdout_orig = self.stdout
4222-
try:
4223-
# redirect our internal stdout
4224-
self.stdout = cast(TextIO, result)
4225-
help_func()
4226-
finally:
4227-
with self.sigint_protection:
4228-
# restore internal stdout
4229-
self.stdout = stdout_orig
4230-
doc = result.getvalue()
4212+
doc: str | None
4213+
4214+
# Non-argparse commands can have help_functions for their documentation
4215+
if command in topics:
4216+
help_func = getattr(self, constants.HELP_FUNC_PREFIX + command)
4217+
result = io.StringIO()
4218+
4219+
# try to redirect system stdout
4220+
with contextlib.redirect_stdout(result):
4221+
# save our internal stdout
4222+
stdout_orig = self.stdout
4223+
try:
4224+
# redirect our internal stdout
4225+
self.stdout = cast(TextIO, result)
4226+
help_func()
4227+
finally:
4228+
with self.sigint_protection:
4229+
# restore internal stdout
4230+
self.stdout = stdout_orig
4231+
doc = result.getvalue()
42314232

4232-
else:
4233-
doc = cmd_func.__doc__
4233+
else:
4234+
doc = cmd_func.__doc__
42344235

4235-
# Attempt to locate the first documentation block
4236-
cmd_desc = strip_doc_annotations(doc) if doc else ''
4236+
# Attempt to locate the first documentation block
4237+
cmd_desc = strip_doc_annotations(doc) if doc else ''
42374238

4238-
# Add this command to the table
4239-
topics_table.add_row(command, cmd_desc)
4239+
# Add this command to the table
4240+
topics_table.add_row(command, cmd_desc)
42404241

4241-
category_grid.add_row(topics_table)
4242-
self.poutput(category_grid, "")
4242+
category_grid.add_row(topics_table)
4243+
self.poutput(category_grid, "")
42434244

42444245
def columnize(self, str_list: list[str] | None, display_width: int = 80) -> None:
42454246
"""Display a list of single-line strings as a compact set of columns.

0 commit comments

Comments
 (0)