-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.zsh
78 lines (72 loc) · 1.99 KB
/
log.zsh
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
#!/bin/zsh
# This script looks for the error messages of desired log level for the desired file you want to compile [rapport/article/documentation/tests]
usage="Usage: $0\n\t\t▶ debug level\n\t\t[--error] [--warning] [--info] [--help]\n\t\t▶ targeted file\n\t\t[--type] r/a/d/t"
if (( $# == 0 )); then
echo $usage
echo "known bug : pass -t before level -e/-w/-i"
echo "example : zsh log.zsh -t r -e"
exit 0
fi
file="rapport" # default value
# ~ parsing arguments
# choose the file
# pattern according to log level
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-e|--error)
pattern="^(Error:|!).*"
shift # Remove argument name from processing
# shift # Remove argument value from processing
;;
-i|--info)
# value="$2"
pattern="Info:"
shift # Remove argument name from processing
# shift # Remove argument value from processing
;;
-w|--warning)
# value="$2"
pattern="Warning:"
shift # Remove argument name from processing
# shift # Remove argument value from processing
;;
-t|--type)
value="$2"
if [[ -z $2 ]]; then
echo "please provide the file you want to compile"
exit 1
fi
case "$value" in
a|article)
file="rapport_article"
;;
r|rapport)
file="rapport"
;;
d|document)
file="documentation"
;;
# ℹ️ deprecated
# t|test)
# file="tests"
# ;;
esac
shift # Remove argument name from processing
shift # Remove argument value from processing
;;
-h|--help)
# value="$2"
echo "$usage"
exit 0
# shift # Remove argument name from processing
# shift # Remove argument value from processing
;;
*) # Unknown option
echo "Unknown option: $1"
exit 1
;;
esac
done
# ~ executed command
batgrep --color -i -B 0 -A 12 "${pattern}" "aux_files/${file}.log"