import json


def getCommandsFromLog(inFile,filterList,coverage):
    """
    Get commands from a log

    Parameters
    ----------
    inFile : str
        path to pyrpipe log file.
    filterList : str
        list of commands to ignore.
    coverage : char
        type of commands to report all, passed or failed: a,p, i.

    Returns
    -------
    commands : TYPE
        DESCRIPTION.

    """
    with open(inFile) as f:
        data=f.read().splitlines()
    commands=[]
    for l in data:
        if not l.startswith("#"):
            thisLog=json.loads(l)
            thisName=thisLog["cmd"].split(' ')[0]
            if filterList and thisName in filterList:
                continue
            status=int(thisLog['exitcode'])
            #skip passed
            if coverage=='i' and status==0:
                continue
            #skip failed
            if coverage=='p' and status!=0:
                continue
            
            commands.append(thisLog["cmd"])
            
    return commands