2021-08-09 00:29:38 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
yapf_args=('--recursive' '--parallel')
|
|
|
|
autoflake_args=('--recursive' '--remove-unused-variables' '--remove-all-unused-imports' '--expand-star-imports' '--remove-duplicate-keys')
|
|
|
|
|
|
|
|
format() {
|
2022-08-15 05:50:20 +02:00
|
|
|
files=("$@")
|
2022-08-16 18:20:06 +02:00
|
|
|
if [[ -z "${files[*]}" ]]; then
|
2022-08-15 05:50:20 +02:00
|
|
|
files=(".")
|
|
|
|
fi
|
|
|
|
|
|
|
|
yapf "${yapf_args[@]}" "${files[@]}"
|
|
|
|
autoflake "${autoflake_args[@]}" "${files[@]}"
|
2021-08-09 00:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$1" == "--check" ]]; then
|
|
|
|
yapf_args+=('--diff')
|
2022-08-15 05:50:20 +02:00
|
|
|
shift
|
|
|
|
[[ "$(format "$@" | tee /dev/stderr | wc -c)" == "0" ]]
|
2021-08-09 00:29:38 +02:00
|
|
|
else
|
|
|
|
yapf_args+=('--in-place')
|
|
|
|
autoflake_args+=('--in-place')
|
2022-08-15 05:50:20 +02:00
|
|
|
format "$@"
|
2021-08-09 00:29:38 +02:00
|
|
|
fi
|