diff options
Diffstat (limited to 'bin/tc_pyformat')
-rwxr-xr-x | bin/tc_pyformat | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/tc_pyformat b/bin/tc_pyformat new file mode 100755 index 00000000..21eceebe --- /dev/null +++ b/bin/tc_pyformat @@ -0,0 +1,36 @@ +#!/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="--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 |