-
Notifications
You must be signed in to change notification settings - Fork 2
/
format
executable file
·53 lines (42 loc) · 1.32 KB
/
format
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
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
version=$(sed -n 's/ktlint = "\(.*\)"/\1/p' gradle/libs.versions.toml)
url="https://github.com/pinterest/ktlint/releases/download/$version/ktlint"
# Set the destination directory and file name
destination_dir="tmp"
file_name="ktlint-$version"
mkdir -p $destination_dir
# setting nullglob ensures proper behavior if nothing matches the glob
shopt -s nullglob
for file in $destination_dir/ktlint-*; do
if [[ "$file" != "$destination_dir/$file_name" ]]; then
rm "$file"
fi
done
shopt -u nullglob
# Check if the file already exists in the destination directory
if [ ! -e "$destination_dir/$file_name" ]; then
if command -v curl >/dev/null 2>&1; then
curl -LJO "$url"
mv "ktlint" "$destination_dir/$file_name"
elif command -v wget >/dev/null 2>&1; then
wget -O "$destination_dir/$file_name" "$url"
else
echo "Error: curl or wget not found. Please install either curl or wget."
exit 1
fi
chmod +x "$destination_dir/$file_name"
fi
should_format=true
for arg in "$@"; do
if [ "$arg" == "--no-format" ]; then
should_format=false
set -- "${@//--no-format/}"
break
fi
done
args=()
if [ "$should_format" = true ]; then
args+=("--format")
fi
args+=("$@")
"$destination_dir/$file_name" **/*.kt **/*.kts \!**/build/** \!Dangerfile.df.kts --color --color-name=YELLOW "${args[@]}"