def commit(ref, message, diff):
    fields = parse(message)
    if not reduce(operator.and_, map(lambda x: x in fields.keys(), REQUIRED_FIELDS)):
        raise Exception("HENRY: Missing fields in commit message")
    uID = firebase_utils.getUserID(ref, fields["email"])
    pID = firebase_utils.getProjectID(ref, fields["project"])
    mID = firebase_utils.getMilestoneID(ref, pID, fields["milestone"])
    tID = firebase_utils.getTaskID(ref, pID, mID, fields["task"])
    firebase_utils.commit(
        ref,
        fields["message"],
        uID,
        pID,
        mID,
        tID,
        fields["hours"],
        fields["status"],
        fields["added_lines_of_code"],
        fields["removed_lines_of_code"],
    )
    if "pp" in fields:
        uID = firebase_utils.getUserID(ref, fields["pp"])
        firebase_utils.commit(
            ref,
            fields["message"],
            uID,
            pID,
            mID,
            tID,
            fields["hours"],
            fields["status"],
            fields["added_lines_of_code"],
            fields["removed_lines_of_code"],
        )
def commit(ref,message,diff):
    fields = parse(message)
    if not reduce(operator.and_,map(lambda x: x in fields.keys(),REQUIRED_FIELDS)):
        raise Exception('HENRY: Missing fields in commit message')
    uID = firebase_utils.getUserID(ref,fields['email'])
    pID = firebase_utils.getProjectID(ref,fields['project'])
    mID = firebase_utils.getMilestoneID(ref,pID,fields['milestone'])
    tID = firebase_utils.getTaskID(ref,pID,mID,fields['task'])
    firebase_utils.commit(ref,fields['message'],uID,pID,mID,tID,fields['hours'],fields['status'],fields['added_lines_of_code'],fields['removed_lines_of_code'])
    else:
        print 'This Git repository is not yet connected to Henry'
        print 'Connect it with'
        print '   henry init <project name>'


if __name__ == '__main__':
    multiprocessing.freeze_support()    # this is a windows thing
    ref = firebase.FirebaseApplication(firebase_url,None)
    sys.argv = [v.strip() for v in sys.argv]
    try:
        if len(sys.argv) == 1:
            usage()
        elif sys.argv[1] == 'init':
            try:
                pID = firebase_utils.getProjectID(ref,sys.argv[2]) 
            except:
                traceback.print_exc(file=sys.stdout)
                print 'HENRY Error: Invalid or nonexistant Henry project name'
                print '   henry init <project name>'
                exit(1)
            try:
                email = git_utils.getEmail()
                userID = firebase_utils.getUserID(ref,email)
            except:
                traceback.print_exc(file=sys.stdout)
                print 'HENRY Error: Invalid or unregistered Git email address'
                print '   henry init <project name>'
                exit(1)
            initialize_git(pID,OPSYS)
        elif sys.argv[1] in {'version','-version','--version','-v'}:
def prompt(ref):
    sys.stdin = open('/dev/tty')

    def_uID, def_pID, def_mID, def_tID, def_status = getDefaults()
   
    if def_uID != None:
        uID = def_uID
    else:
        sys.stdout.write('Email: ')
        sys.stdout.flush()
        email = raw_input()
        uID = firebase_utils.getUserID(ref,email)

    if def_pID != None:
        print 'Active projects (defaults to '+def_pID+'):'
    else:
        print 'Active projects:'
    sys.stdout.flush()
    idsByIndex = [] ; index = 1
    for pID, pName in firebase_utils.getActiveProjects(ref,uID).iteritems():
        print ' - '+str(index)+'. '+pName
        idsByIndex = idsByIndex + [pID]
        index = index + 1
    sys.stdout.write('Project: ')
    sys.stdout.flush()
    project = raw_input()
    if project.isdigit() and int(project) <= len(idsByIndex):
        pID = idsByIndex[int(project)-1]
    elif project == '' and def_pID != 0:
        pID = def_pID
    else:
        pID = firebase_utils.getProjectID(ref,project)

    if def_mID != None:
        print 'Active milestones (defaults to '+def_mID+'):'
    else:
        print 'Active milestones:'
    sys.stdout.flush()
    idsByIndex = [] ; index = 1
    for mID, mName in firebase_utils.getActiveMilestones(ref,uID,pID).iteritems():
        print ' - '+str(index)+'. '+mName
        idsByIndex = idsByIndex + [mID]
        index = index + 1
    sys.stdout.write('Milestone: ')
    sys.stdout.flush()
    milestone = raw_input()
    if milestone.isdigit() and int(milestone) <= len(idsByIndex):
        mID = idsByIndex[int(milestone)-1]
    elif milestone == '' and def_mID != 0:
        mID = def_mID
    else:
        mID = firebase_utils.getMilestoneID(ref,pID,milestone)

    if def_tID != None:
        def_task = firebase_utils.getTask(ref,pID,mID,def_tID)
        print 'Tasks assigned to you (defaults to '+def_task+'):'
    else:
        print 'Tasks assigned to you:'
    idsByIndex = [] ; index = 1
    for tID, tName in firebase_utils.getAssignedTasks(ref,uID,pID,mID).iteritems():
        print ' - '+str(index)+'. '+tName
        idsByIndex = idsByIndex + [tID]
        index = index + 1
    sys.stdout.write('Task: ')
    sys.stdout.flush()
    task = raw_input()
    if task.isdigit() and int(task) <= len(idsByIndex):
        tID = idsByIndex[int(task)-1]
    elif task == '' and def_tID != 0:
        tID = def_tID
    else:
        tID = getTaskID(pID,mID,task)


    sys.stdout.write('Hours: ')
    sys.stdout.flush()
    hours = raw_input()


    if def_status != None:
        print 'Select status (defaults to '+def_status+'):'
    else:
        print 'Select status:'
    possibleStatuses = ['New', 'Implementation', 'Testing', 'Verify', 'Regression', 'Closed']
    for i in range(len(possibleStatuses)):
        print ' - ' + str(i+1) + ': ', possibleStatuses[i]
    sys.stdout.write('Status: ')
    sys.stdout.flush()
    status = raw_input()
    if status.isdigit() and (int(status) <= len(possibleStatuses)):
        status = possibleStatuses[int(status)-1]
    elif status == '' and def_status != 0:
        status = def_status
    else:
        print 'HENRY: Invalid status, commit failed'
        exit(1)
    print 'I should be returning' 
    return uID,pID,mID,tID,hours,status