-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathflogg
executable file
·46 lines (36 loc) · 1.07 KB
/
flogg
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
# checks the complexity of a file in HEAD
filepath=$1
function calculate_complexity_difference() {
previous_complexity=$(git show HEAD:$filepath | flog | grep 'flog total' | awk '{print $1}' | sed 's/\://g')
current_complexity=$(flog $filepath | grep 'flog total' | awk '{print $1}' | sed 's/\://g')
difference=$(echo $previous_complexity - $current_complexity | bc)
}
function print_complexity_diff() {
calculate_complexity_difference
echo "Previous Complexity: $previous_complexity"
echo -e "Current Complexity: $current_complexity\n"
echo "You have reduced the total complexity by: $difference"
}
function invalid_filepath() {
[[ ! -f $filepath ]]
}
function missing_params() {
[[ -z $filepath ]]
}
function print_invalid_filepath_message() {
echo "File not found: $filepath"
exit 1
}
function print_usage_message() {
echo 'Usage: flogg <filepath>'
exit 1
}
function main() {
if missing_params; then
print_usage_message
elif invalid_filepath; then
print_invalid_filepath_message
fi
print_complexity_diff
}
main