forked from square/spacecommander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format-objc-files.sh
executable file
·43 lines (36 loc) · 988 Bytes
/
format-objc-files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# format-objc-files.sh
# Formats Objective-C files in place.
# Copyright 2015 Square, Inc
#
# Default behavior: formats staged Objective-C files, but doesn't stage these changes.
# Optional arguments:
# -s : staged the changes in git.
# <git SHA> : this SHA is used with `git diff` to generate the list of files to format.
IFS=$'\n'
export CDPATH=""
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "$DIR"/lib/common-lib.sh
stage_flag=0
optional_base_sha=$2
if [ "$1" == "-s" ]; then
stage_flag=1
else
optional_base_sha=$1
echo "Not staging changes. Run '${BASH_SOURCE[0]} -s $1' to stage them."
fi
objc_files=$(objc_files_to_format "$optional_base_sha")
[ -z "$objc_files" ] && exit 0
function format_objc() {
for file in $objc_files; do
$("$DIR"/format-objc-file.sh "$file")
echo "Formatted $file"
if [ "$stage_flag" -eq 1 ]; then
$(git add "$file")
echo -e "\tStaged $file"
fi
done
}
format_objc
echo "Formatting complete."
exit 0