mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-07-23 00:35:33 +02:00
set-alias-page.py: improve regex pattern (#14368)
This commit is contained in:
parent
49c7b211e2
commit
aaf688c301
1 changed files with 13 additions and 3 deletions
|
@ -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 ""
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue