"""
Search for target.txt

"""

import os
import sys



def print_contents(path: str) -> str:
    """
    Given a path open the file on the path and print contents
    """
    with open(path, 'r') as f:
        lines = f.readlines()
    for line in lines:
        print(line)


def search_dirs(dir):
    """
    Givent a home directory designation search all branches for target.txt
    """
    output_paths = []
    for contents in os.walk(dir):
        if 'target.txt' in contents[2]:
            target_path = contents[0] + '/target.txt'
            output_paths.append(target_path)

    # here we'll have to split each path and seach for the key terms
    # and call the appropriate function accordingly 
    for path in output_paths:
        print_contents(path)

    return output_paths




if __name__ == "__main__":
#    current_dir = os.getcwd()
    current_dir = os.environ['CURRENT_DIR']  # as an alternative to main path
    search_dirs(current_dir)