blob: 63a6e9471323fd3231d0644dcb86d1367ccbb003 [file] [log] [blame]
#!/bin/bash
# Usage: tc_pyformat <list of pyformat options> file1.py file2.py ...
#
# Most common option is -i, which makes formatting changes in place.
set -u
PF=pyformat
PF_OPTIONS="--remove_trailing_comma --yapf --force_quote_type=single"
PF_USER_OPTIONS=""
if [[ -z "$(type -t ${PF})" ]]; then
echo "Error: ${PF} not in your path."
exit 1
fi
while [[ "$1" == -* ]]; do
PF_USER_OPTIONS+=" $1"
shift
done
FILES=$*
PF_OPTIONS+=${PF_USER_OPTIONS}
for f in ${FILES}; do
if [[ $f != *.py ]]; then
echo "Error: File $f is not a python file"
exit 2
elif [[ -x $f ]]; then
${PF} ${PF_OPTIONS} $f
elif [[ -f $f ]]; then
${PF} --remove_shebang ${PF_OPTIONS} $f
else
echo "Error: File $f does not exist"
exit 2
fi
done