diff --git a/tldr.py b/tldr.py index c99e133..e384248 100755 --- a/tldr.py +++ b/tldr.py @@ -529,44 +529,21 @@ 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) + 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: command = '-'.join(options.command).lower()