#!/bin/bash

set -e

# capture the changed files that have been staged
changed_files=$(git diff --staged --name-only)

for file in ${changed_files}
do
	if [[ "${file##*.}" == "py" ]]; then
		if command -v yapf > /dev/null; then
			echo "Run yapf on ${file}"
			yapf ${file} -i
			git add ${file}
		fi

		if command -v flake8 > /dev/null; then
			echo "Run flake8 on ${file}"
			flake8 ${file}
		fi
	fi
done

