From a6129a82bdd6b5d3c3408f1daadedc2453a22845 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Mon, 15 Aug 2022 05:50:20 +0200 Subject: [PATCH] format.sh: allow selecting file paths --- format.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/format.sh b/format.sh index de5a6b7..1514aee 100755 --- a/format.sh +++ b/format.sh @@ -4,16 +4,24 @@ yapf_args=('--recursive' '--parallel') autoflake_args=('--recursive' '--remove-unused-variables' '--remove-all-unused-imports' '--expand-star-imports' '--remove-duplicate-keys') format() { - yapf "${yapf_args[@]}" . - autoflake "${autoflake_args[@]}" . + files=("$@") + if [[ -z "${files[@]}" ]]; then + files=(".") + fi + + yapf "${yapf_args[@]}" "${files[@]}" + autoflake "${autoflake_args[@]}" "${files[@]}" } + + if [[ "$1" == "--check" ]]; then yapf_args+=('--diff') - [[ "$(format | tee /dev/stderr | wc -c)" == "0" ]] + shift + [[ "$(format "$@" | tee /dev/stderr | wc -c)" == "0" ]] else yapf_args+=('--in-place') autoflake_args+=('--in-place') - format + format "$@" fi