-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdotnet-format-wrapper
More file actions
executable file
·81 lines (72 loc) · 1.65 KB
/
dotnet-format-wrapper
File metadata and controls
executable file
·81 lines (72 loc) · 1.65 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# Wrapper for the dotnet-format command that is compatible with pre-commit.
PROJECT=""
EXCLUDE=""
VERBOSITY=""
FOLDER=0
EXCLUDE=()
FILES=()
# Keep the project if it's a file/folder that is not a cs file.
if [[ -f $1 ]] && ([[ $1 == *proj ]] || [[ $1 == *sln ]]); then
PROJECT="$1"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--folder|-f)
FOLDER=1
;;
--exclude)
while [[ ! -z $2 ]] && [[ $2 != -* ]]; do
EXCLUDE+=($2)
shift
done
;;
--verbosity|-v)
VERBOSITY=$2
shift
;;
--check|--version)
# Ignore these no-arg options.
;;
--report|--include|--)
# Ignore these arguments.
shift
;;
*)
# Paths relative to the PWD that need to be made relative for --include.
FILES+=($1)
;;
esac
shift
done
# Filenames are relative to the workspace.
WORKSPACE_DIR="."
if [[ ! -z $PROJECT ]]; then
WORKSPACE_DIR=$(dirname "$PROJECT")
fi
INCLUDE=()
for f in "${FILES[@]}"; do
RELATIVE_PATH=$(realpath --relative-to="${WORKSPACE_DIR}" "$f")
# Only pass in paths that are relative to the project.
if [[ "$RELATIVE_PATH" != "../"* ]]; then
INCLUDE+=("${RELATIVE_PATH}")
fi
done
ARGS=()
if [[ ! -z $PROJECT ]]; then
ARGS+=("$PROJECT")
fi
if [[ $FOLDER -eq 1 ]]; then
ARGS+=("--folder")
fi
if [[ ! -z $VERBOSITY ]]; then
ARGS+=("--verbosity" $VERBOSITY)
fi
if [[ ${#EXCLUDE[@]} -gt 0 ]]; then
ARGS+=("--exclude" "${EXCLUDE[@]}")
fi
if [[ ${#INCLUDE[@]} -gt 0 ]]; then
ARGS+=("--include" "${INCLUDE[@]}")
fi
#echo "Running: /opt/dotnet-format/dotnet-format" "${ARGS[@]}"
exec /opt/dotnet-format/dotnet-format "${ARGS[@]}"