-
Notifications
You must be signed in to change notification settings - Fork 3
/
qk.sh
executable file
·84 lines (73 loc) · 2.04 KB
/
qk.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Show usage if no arguments provided
if [ $# -lt 2 ]; then
echo "Usage: qk <JIRA-ID> [-d|-f|-s]"
echo " -d: Download logs (qklogs)"
echo " -f: Find request by ID (qkfind)"
echo " -s: Search in logs (qksearch)"
exit 1
fi
# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
QKLOGS_PATH="$SCRIPT_DIR/qklogs/qklogs.sh"
QKFIND_PATH="$SCRIPT_DIR/qkfind.sh"
QKSEARCH_PATH="$SCRIPT_DIR/qksearch.sh"
JIRA_ID="$1"
ACTION="$2"
LOGS_DIR="$HOME/Downloads/logs_${JIRA_ID}"
# Function to find log file
find_log_file() {
local base_dir="$1"
local log_file=$(find "$base_dir" -maxdepth 1 -type f -name "flutter-api*.log" | head -n 1)
if [[ -n "$log_file" ]]; then
echo "$log_file"
else
echo "$base_dir/flutter-api.log"
fi
}
if [[ -n "${LOG_OUTPUT_FOLDER_NAME}" ]]; then
LOG_FILE=$(find_log_file "$LOGS_DIR/${LOG_OUTPUT_FOLDER_NAME}")
else
LOG_FILE=$(find_log_file "$LOGS_DIR/merged")
fi
# Function to check if logs exist
check_logs() {
if [ ! -f "$LOG_FILE" ]; then
echo "❌ Log file not found at: $LOG_FILE"
echo "💡 Try downloading logs first with: qk $JIRA_ID -d"
exit 1
fi
}
case "$ACTION" in
"-d")
# Call qklogs with full path
"$QKLOGS_PATH" "$JIRA_ID"
;;
"-f")
check_logs
# Use third argument if provided, otherwise prompt
if [ -n "$3" ]; then
REQUEST_ID="$3"
else
echo -n "Enter request ID to find: "
read REQUEST_ID
fi
"$QKFIND_PATH" "$LOG_FILE" "$REQUEST_ID"
;;
"-s")
check_logs
# Use third argument if provided, otherwise prompt
if [ -n "$3" ]; then
SEARCH_TERM="$3"
else
echo -n "Enter search term: "
read SEARCH_TERM
fi
"$QKSEARCH_PATH" "$LOG_FILE" "$SEARCH_TERM"
;;
*)
echo "❌ Invalid action: $ACTION"
echo "Usage: qk <JIRA-ID> [-d|-f|-s]"
exit 1
;;
esac