#!/usr/bin/env python3
import argparse


class bcolors:
    HEADER = "\033[95m"
    OKBLUE = "\033[94m"
    OKCYAN = "\033[96m"
    okgreen = "\033[92m"
    warning = "\033[93m"
    fail = "\033[91m"
    endc = "\033[0m"
    bold = "\033[1m"
    underline = "\033[4m"


parser = argparse.argumentparser(description="finds specific content files")
parser.add_argument(
    "word", metavar="f", type=str, help="a program to print content of files"
)

parser.add_argument(
    "files",
    metavar="f",
    type=str,
    nargs="+",
    help="a program to print content of files",
)

args = parser.parse_args()


def grep(args):
    def strip_new_line(word):
        return word.rstrip()

    def check_if_word_exist(word):
        return args.word in word

    def get_word_lines():

        for file in args.files:
            with open(file, "r") as file_obj:
                content = [strip_new_line(content) for content in file_obj.readlines()]
                filter_object = [
                    filtered_object
                    for filtered_object in content
                    if check_if_word_exist(filtered_object)
                ]
        return filter_object

    def color_word():
        for word in get_word_lines():
            # Add color to specific word
            print(f"{word}".replace(args.word, bcolors.FAIL + args.word + bcolors.ENDC))

    color_word()


grep(args)

# example usage
# python grep.py google ping.txt
