-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerate_error_codes_yml.sh
More file actions
40 lines (36 loc) · 984 Bytes
/
generate_error_codes_yml.sh
File metadata and controls
40 lines (36 loc) · 984 Bytes
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
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
# Usage
# show_code_arround_error_codes.sh <regex-pattern1> <regex-pattern2>
# pattern filter line of <filename>:<linenumber>|<error-code>
# multiple pattern get merged with | to an or construction
error_codes=$(bash find_error_codes.sh | awk '{print $1 "|" $2 "-" $3 "-" $4}')
awkcommand='
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }
{
file=$1
line=$2
code=$3
cmd="sed -n " $2 "p " $1
cmd | getline cmdout
close(cmd)
print "- \"" code "\":"
print " \"file\": \"" file "\""
print " \"line\": \"" line "\""
print " \"description\":"
print " - \"" trim(cmdout) "\""
print " - \"\""
print " \"recommendations\":"
print " - \"\""
}
'
echo $error_codes \
| tr " " "\n" \
| tr "|" " " \
| tr ":" " " \
| awk "$awkcommand" \
# | xargs -n 1 -I {} echo "bash -c '{}'"