set-alias-page.py: improve regex pattern (#14368)

This commit is contained in:
Jack Lin
2024-10-30 10:04:17 -07:00
committed by GitHub
parent 49c7b211e2
commit aaf688c301

View File

@@ -186,11 +186,21 @@ def get_alias_page(path: Path) -> str:
if not path.exists():
return ""
command_count = 0
command_name = ""
with path.open(encoding="utf-8") as f:
for line in f:
# match alias (`tldr <alias>`)
if match := re.search(r"^`tldr (.+)`", line):
return match[1]
# match alias page pattern "> This command is an alias of `example`."
if match := re.search(r"^> This command is an alias of `(.+)`\.$", line):
command_name = match[1]
# count the lines matching pattern "`...`"
if re.match(r"^`[^`]+`$", line.strip()):
command_count += 1
if command_count == 1:
return command_name
return ""