From 2b828c164bdd00e57b1d142dffebd38fc10fe4c5 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 4 Mar 2020 10:23:00 -0800 Subject: [PATCH] [script] make pretty python or clang (#4632) Reformating cpp ```bash ./script/make-pretty clang ``` Reformating python ```bash ./script/make-pretty python ``` --- script/make-pretty | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/script/make-pretty b/script/make-pretty index 6db40cf2e..34bee9a6a 100755 --- a/script/make-pretty +++ b/script/make-pretty @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -set -e -x -o pipefail +set -euo pipefail readonly TMP_DIR="/tmp/ot-make-pretty-$(date +%Y%m%d%H%M%S)" readonly SRC_DIR="$PWD" @@ -40,7 +40,7 @@ at_exit() exit $EXIT_CODE } -make_pretty() +do_clang_format() { ./bootstrap mkdir "${TMP_DIR}" @@ -49,11 +49,27 @@ make_pretty() make pretty } +do_python_format() +{ + python3 -m yapf --verbose --style google -ipr "${SRC_DIR}/tests" "${SRC_DIR}/tools" +} + main() { - trap at_exit INT TERM EXIT - make_pretty - python3 -m yapf --style google -ipr "${SRC_DIR}/tests" "${SRC_DIR}/tools" + if [ $# == 0 ]; then + trap at_exit INT TERM EXIT + do_clang_format + do_python_format + elif [ "$1" == 'python' ]; then + do_python_format + elif [ "$1" == 'clang' ]; then + do_clang_format + else + >&2 echo "Unsupported action: $1" + # 128 for Invalid arguments + exit 128 + fi + } main "$@"