1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #!/bin/bash
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SCRIPT_PATH=$(dirname $0)
- CONFIG="$SCRIPT_PATH/uncrustify.cfg"
- EXE="$SCRIPT_PATH/../node_modules/.bin/uncrustify"
-
- function Usage() {
- echo "Formats code using uncrustify."
- echo "Usage: bin/uncrustify.sh --changed # Runs on changed (staged or not) files"
- echo " bin/uncrustify.sh --staged # Runs on staged files"
- echo " bin/uncrustify.sh --all # Runs on all source files under the current directory"
- echo " bin/uncrustify.sh --check-file file # Returns 1 if the given file requires changes, 0 otherwise."
- echo " bin/uncrustify.sh files # Runs on the given files"
- exit 1
- }
-
- function VerifyEnv() {
- if ! which "$EXE" > /dev/null; then
- echo "uncrustify binary not found in the cordova-ios repo."
- echo "In the repo root, install via npm: npm install"
- exit 1
- fi
- }
-
- function FilterFileList() {
-
-
- for f in "$@"; do
-
- [[ ! -e "$f" ]] && continue
-
- [[ "$f" != *.[hm] ]] && continue
-
- [[ "$f" == *JSONKit* ]] && continue
- echo $f
- done
- }
-
- function FilterAndRun() {
- files=$(FilterFileList "$@")
-
- if [[ -z "$files" ]]; then
- echo No files to uncrustify.
- exit 2
- else
- echo "$files" | xargs uncrustify -l OC --no-backup -c "$CONFIG"
- fi
- }
-
- if [[ "$1" = "--changed" ]]; then
- VerifyEnv
- files=$(git status --porcelain | sed s:...::)
- FilterAndRun $files
- elif [[ "$1" = "--staged" ]]; then
- VerifyEnv
- files=$(git diff --cached --name-only)
- FilterAndRun $files
- elif [[ "$1" = "--all" ]]; then
- VerifyEnv
- files=$(find .)
- FilterAndRun $files
- elif [[ "$1" = "--check-file" ]]; then
- "$EXE" -q -l OC -c "$CONFIG" -f "$2" | cmp --quiet - "$2"
- elif [[ "$1" = "--filter" ]]; then
- FilterFileList "$@"
- elif [[ "$1" = -* ]]; then
- Usage
- else
- VerifyEnv
- FilterAndRun "$@"
- fi
|