From d13239c711a517c3d599c1f2c58e4025004bfce4 Mon Sep 17 00:00:00 2001 From: CleanMachine1 <78213164+CleanMachine1@users.noreply.github.com> Date: Sun, 28 Apr 2024 17:43:02 +0200 Subject: [PATCH 1/2] tldr.py: fix search --- tldr.py | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/tldr.py b/tldr.py index c99e133..d10970e 100755 --- a/tldr.py +++ b/tldr.py @@ -529,43 +529,24 @@ def main() -> None: output(open_file.read().encode('utf-8').splitlines(), plain=options.markdown) elif options.search: - command = '-'.join(options.command) - page = None - maxprob = 0 - searchquery = options.search.split(' ') - - platforms = get_platform_list() - for i in get_commands(platforms): - if i.startswith(command): - for p in platforms: - result = load_page_from_cache(i, p, options.language) - if result is not None and have_recent_cache(i, p, options.language): - break - if result is None: - raise SystemExit("Please update cache") - result = result.decode("utf-8") - result = result.split() - for word in searchquery: - prob = 0 - for line in result: - line = line.lower() - if word in line: - prob += 1 - if line.startswith("#"): - prob += 7 - elif line.startswith(">"): - prob += 5 - elif line.startswith("-"): - prob += 2 - if prob > maxprob: - maxprob = prob - page = i - - if page: - result = get_page(page, None, options.platform, options.language) - output(result, plain=options.markdown) + search_term = options.search.lower() + commands = get_commands(options.platform, options.language) + print(commands) + if not commands: + print("Update cache, no commands to check from.") + return + similar_commands = [] + for command in commands: + + if search_term in command.lower(): + similar_commands.append(command) + + if similar_commands: + print("Similar commands found:") + print('\n'.join(similar_commands)) + return else: - print("No results found") + print("No commands matched your search term.") else: try: From 54d6b4b37a7b9aa4162bb73dc174d8c524688f34 Mon Sep 17 00:00:00 2001 From: CleanMachine1 <78213164+CleanMachine1@users.noreply.github.com> Date: Sun, 28 Apr 2024 17:49:05 +0200 Subject: [PATCH 2/2] remove print statement and whitespace --- tldr.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tldr.py b/tldr.py index d10970e..e384248 100755 --- a/tldr.py +++ b/tldr.py @@ -531,23 +531,19 @@ def main() -> None: elif options.search: search_term = options.search.lower() commands = get_commands(options.platform, options.language) - print(commands) if not commands: print("Update cache, no commands to check from.") return similar_commands = [] for command in commands: - if search_term in command.lower(): similar_commands.append(command) - if similar_commands: print("Similar commands found:") print('\n'.join(similar_commands)) return else: print("No commands matched your search term.") - else: try: command = '-'.join(options.command).lower()