Skip to content

Commit

Permalink
Fixed crash for subtopic highlighting (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull authored Jan 11, 2024
1 parent 5ee8219 commit c6a8ea2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
38 changes: 16 additions & 22 deletions osxphotos/cli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ def get_subtopic_help(cmd: click.Command, ctx: click.Context, subtopic: str):
if options:
option_str = format_options_help(options, ctx, highlight=subtopic)
formatter.write(f"Options that match '[highlight]{subtopic}[/highlight]':\n")
formatter.write_paragraph()
formatter.write(option_str)
return formatter.getvalue() + "\n" + option_str
else:
formatter.write(f"No options match '[highlight]{subtopic}[/highlight]'")
return formatter.getvalue()
return formatter.getvalue()


def get_matching_options(
Expand Down Expand Up @@ -176,28 +175,23 @@ def format_options_help(
"""
formatter = click.HelpFormatter(width=HELP_WIDTH)
opt_help = [opt.get_help_record(ctx) for opt in options]
formatter.write_dl(opt_help)

help_text = formatter.getvalue()
if highlight:
# convert list of tuples to list of lists
opt_help = [list(opt) for opt in opt_help]
for record in opt_help:
record[0] = re.sub(
f"({highlight})",
"[highlight]\\1[/highlight]",
record[0],
re.IGNORECASE,
)

record[1] = re.sub(
f"({highlight})",
"[highlight]\\1[/highlight]",
record[1],
re.IGNORECASE,
)
def _highlight(match):
return f"[highlight]{match.group(0)}[/]"

# convert back to list of tuples as that's what write_dl expects
opt_help = [tuple(opt) for opt in opt_help]
formatter.write_dl(opt_help)
return formatter.getvalue()
# add highlight tags
help_text = re.sub(
f"{highlight}",
_highlight,
help_text,
flags=re.IGNORECASE,
)

return help_text


def format_help_text(text: str, formatter: click.HelpFormatter):
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PLDeferredCriticalMaintenanceTask</key>
<date>2024-01-10T07:11:47Z</date>
</dict>
</plist>

0 comments on commit c6a8ea2

Please sign in to comment.