set-alias-page.py: improve regex pattern (#14368)
This commit is contained in:
@@ -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 ""
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user