<commit_before>#!/usr/bin/env python3
"""
cmake documentation reader

@author: <NAME> <<EMAIL>>
@license: Apache 2.0
"""
import os
import shlex
import subprocess
import sys

from collections import namedtuple

__appname__ = "cmakehelp"
__version__ = "1.0.0"
__license__ = "Apache 2.0"

DESCRIPTION = """\
cmakehelp makes it easier to search CMake reference documentation. Just enter
any term to get a list of the matching command, module, variable or property.
You can then select the topic you want and read it.
"""

SOURCES = ["command", "module", "variable", "property"]

Match = namedtuple("Match", ("source", "topic"))


def error(message):
    print("Error: {}".format(message))


def find_matches(source, term):
    out, err = subprocess.Popen(["cmake", "--help-%s-list" % source],
                                stdout=subprocess.PIPE).communicate()
    lines = str(out, "utf-8").splitlines()
    return [Match(source, x.strip()) for x in lines if term in x.lower()]


def show_doc(match):
    pager = shlex.split(os.environ.get("PAGER", "less"))
    p1 = subprocess.Popen(["cmake", "--help-%s" % match.source, match.topic],
                          stdout=subprocess.PIPE)
    p2 = subprocess.Popen(pager, stdin=p1.stdout)
    p2.wait()


def show_prompt(has_topic):
    if has_topic:
        message = "Enter topic number or search term"
    else:
        message = "Enter search term"
    message += " (empty input or 'q' to quit): "
    try:
        answer = input(message)
    except KeyboardInterrupt:
        print()
        return ""
    answer = answer.lower()
    if answer == "q":
        return ""
    return answer


def main():
    if len(sys.argv) > 1:
        term = sys.argv[1]
    else:
        term = show_prompt(has_topic=False)
        if term is "":<commit_msg>Add argparser and multi term search<commit_after>#!/usr/bin/env python3
"""
cmake documentation reader

@author: <NAME> <<EMAIL>>
@license: Apache 2.0
"""
import argparse
import os
import shlex
import subprocess

from collections import namedtuple

__appname__ = "cmakehelp"
__version__ = "1.0.0"
__license__ = "Apache 2.0"

DESCRIPTION = """\
cmakehelp makes it easier to search CMake reference documentation. Just enter
any term to get a list of the matching command, module, variable or property.
You can then select the topic you want and read it.
"""

SOURCES = ["command", "module", "variable", "property"]

Match = namedtuple("Match", ("source", "topic"))


def error(message):
    print("Error: {}".format(message))


def find_matches(source, term):
    terms = term.lower().split(" ")

    def match(line):
        line = line.lower()
        for term in terms:
            if term not in line:
                return False
        return True

    out, err = subprocess.Popen(["cmake", "--help-%s-list" % source],
                                stdout=subprocess.PIPE).communicate()
    lines = str(out, "utf-8").splitlines()
    return [Match(source, x.strip()) for x in lines if match(x)]


def show_doc(match):
    pager = shlex.split(os.environ.get("PAGER", "less"))
    p1 = subprocess.Popen(["cmake", "--help-%s" % match.source, match.topic],
                          stdout=subprocess.PIPE)
    p2 = subprocess.Popen(pager, stdin=p1.stdout)
    p2.wait()


def show_prompt(has_topic):
    if has_topic:
        message = "Enter topic number or search term"
    else:
        message = "Enter search term"
    message += " (empty input or 'q' to quit): "
    try:
        answer = input(message)
    except KeyboardInterrupt:
        print()
        return ""
    answer = answer.lower()
    if answer == "q":
        return ""
    return answer


def main():
    parser = argparse.ArgumentParser()
    parser.description = DESCRIPTION
    parser.add_argument("term", nargs="+", help="Search term")
    args = parser.parse_args()

    if args.term:
        term = " ".join(args.term)
    else:
        term = show_prompt(has_topic=False)
        if term is "":
{'fraction_non_alphanumeric': 0.13472676907579956, 'fraction_numerical': 0.007051120624527827, 'mean_word_length': 2.833976833976834, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4063156', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1230, 'n_words': 369}