-
Notifications
You must be signed in to change notification settings - Fork 0
/
getranges.sh
executable file
·68 lines (59 loc) · 1.69 KB
/
getranges.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
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
#!/usr/bin/env bash
# Default values
start=""
lunch=""
minutesOfLunchBreak="30"
# Help function
usage() {
echo "Usage: $0 [-s start] [-l lunch] [-b minutesOfLunchBreak]"
echo " -s: Start time"
echo " -l: Lunch time"
echo " -b: Minutes of lunch break (default: 30)"
exit 1
}
# Parse command-line options
while getopts "hs:l:b:" opt; do
case ${opt} in
h)
usage
;;
s)
start=$OPTARG
;;
l)
lunch=$OPTARG
;;
b)
minutesOfLunchBreak=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" 1>&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." 1>&2
usage
;;
esac
done
shift $((OPTIND -1))
uri="http://localhost:8384/ranges"
if [ -n "$start" ] && [ -n "$lunch" ]; then
uri+="With/$start/$lunch/$minutesOfLunchBreak"
elif [ -n "$minutesOfLunchBreak" ]; then
uri+="/$minutesOfLunchBreak"
fi
#Print uri
echo $uri
echo "---------------------------------------------"
response=$(curl -s $uri)
json=$(echo $response | jq '.')
#Print column headers
echo "Start End Duration Duration in Hours"
# Display the rangeDetails array in a table format with separate columns for start and end times
echo $json | jq -r '.rangeDetails[] | "\(.range.start | sub(".+T"; "") | sub(":00$"; "")) \(.range.end | sub(".+T"; "") | sub(":00$"; "")) \(.duration) \(.durationInHours)"'
echo "---------------------------------------------"
# Display the remaining data with labels
echo "Total Hours: $(echo $json | jq -r '.totalHours')"
echo "Total Hours in HH:MM: $(echo $json | jq -r '.totalHoursInHHMM')"
echo "Expected Lunch Time in HH:MM: $(echo $json | jq -r '.expectedLunchTimeInHHMM')"