-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqsf
executable file
·58 lines (51 loc) · 1.11 KB
/
qsf
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
#!/bin/bash
# Default user
DEFAULT_USER=${DEFAULT_USER:-"vport@ufsc"}
# Initialize variables
USER="$DEFAULT_USER"
ALL_USERS=false
JOB_STATUS=""
FIELDS=()
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-u|--user)
USER="$2"
shift # past argument
shift # past value
;;
-a|--all)
ALL_USERS=true
shift # past argument
;;
-s|--status)
JOB_STATUS="$2"
shift # past argument
shift # past value
;;
-f|--field)
FIELDS+=("$2")
shift # past argument
shift # past value
;;
*)
shift # past unrecognized argument
;;
esac
done
# Create jq filter string
JQ_FILTER=".jobs[]"
if [ "$ALL_USERS" = false ]; then
JQ_FILTER="$JQ_FILTER | select(.owner == \"$USER\")"
fi
if [ -n "$JOB_STATUS" ]; then
JQ_FILTER="$JQ_FILTER | select(.status == \"$JOB_STATUS\")"
fi
# If no fields are specified, output the whole JSON structure
if [ ${#FIELDS[@]} -eq 0 ]; then
JQ_FILTER="$JQ_FILTER"
else
JQ_FILTER="$JQ_FILTER | {$(printf "%s," "${FIELDS[@]}" | sed 's/,$//')}"
fi
# Process JSON from stdin with jq
jq "$JQ_FILTER"