-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions
More file actions
executable file
·179 lines (155 loc) · 3.2 KB
/
functions
File metadata and controls
executable file
·179 lines (155 loc) · 3.2 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
lang=${LANG%_*}
declare verbose
declare -A comments
declare -A META
function base_main()
{
action="_markdown"
# dispatch arguments
while [ ${#} -gt 0 ]; do
case ${1} in
-f|--fix) action="_fix"; shift;;
-c|--check) action="_check"; shift;;
-h|--help) action="_help"; break;;
-d|--description) action="_description"; shift;;
-t|--title) action="_title"; shift;;
--force) force=t; shift;;
-l|--lang) lang=${1}; shift;;
-m|--meta) action="_meta"; shift;;
-v|--verbose) verbose=t; shift;;
--verify) action="_verify"; break;;
*) action="_help"; shift;;
esac
done
if [ "$lang" == "en" ]; then
lang=""
else
lang="_$lang"
fi
case $action in
_verify)
echo -n "verified fixme script"
;;
_fix)
if [ $force ]; then
fix
else
get_translation fix
if [[ $verbose ]]; then
declare -f fix
fi
fi
;;
_check)
if [ $force ]; then
check
else
get_translation check
if [[ $verbose ]]; then
declare -f check
fi
fi
;;
_meta)
local sep=""
echo -n "{"
for key in "${!META[@]}"; do
local v="${META[$key]}"
if [[ $v != "true" && $v != "false" ]]; then
v="\"$v\""
fi
echo -n "$sep\"$key\":$v"
sep=","
done
echo "}"
;;
_description)
get_translation "description"
;;
_title)
head -n1 <<EOF
$(get_translation "description")
EOF
;;
_markdown) base_markdown;;
_help) base_help;;
esac
}
function COMMENT()
{
if [ ${#} -eq 1 ]; then
IFS='\n' read -r -d '' tmp || true;
comments["${1}"]=$tmp
else
IFS='\n' read -r -d '' tmp || true;
comments["${2}_${1}"]=$tmp
fi
}
function get_translation()
{
origin=${comments["$1"]}
locale=${comments["$1$lang"]}
if [ "$locale" ]; then
echo "$locale"
else
echo "$origin"
fi
}
function render_code()
{
echo \`\`\`
echo "$(declare -f $1)"
echo \`\`\`
}
function base_markdown()
{
COMMENT md_check <<EOF
How to check?
EOF
COMMENT zh md_check <<EOF
如何检查?
EOF
COMMENT md_fix <<EOF
How to fix?
EOF
COMMENT zh md_fix <<EOF
如何修复?
EOF
title=$(head -n1 <<EOF
$(get_translation description)
EOF
)
cat <<EOF
# $title
$(get_translation description)
# $(get_translation md_check)
$(get_translation check)
$([[ $verbose ]] && render_code check)
# $(get_translation md_fix)
$(get_translation fix)
$([[ $verbose ]] && render_code fix)
EOF
}
function base_help()
{
cat <<EOF
Options:
-f|--fix) dry run the fix function.
-c|--check) dry run the check function.
-d|--description) print the description of the problem.
-t|--title) show the title of the problem.
-l|--lang) specify display language.
-m|--meta) print the meta data in json format.
-v|--verbose) show code in render document.
-h|--help) print this usage.
--force) force run the function.
--verify) just echo "verified fixme script" for fixme verifying validation of the script
Use fixme client instead use this script directly.
The default action is print the document of
the problem in markdown foramt.
./fix -v > README.md
LANG=zh_CN ./fix -v > README.zh.md
EOF
exit 1
}