-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.jq
executable file
·31 lines (30 loc) · 929 Bytes
/
test.jq
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
def colors:
{
"bold": "\u001b[1m",
"reset": "\u001b[0m",
};
if .[].success == false then
if (.[] | has("error")) and (.[].error | type != "boolean") then
"Error:",
" code: " + (.[].error.code | tostring),
" msg: " + (.[].error.msg | tostring),
halt_error(1)
else
"Wolfram|Alpha did not understand your input",
.[].tips.text // empty
end,
if .[] | has("didyoumeans") then
"inputstring:", " " + (.[].inputstring | tostring),
"didyoumeans:", " " + (.[].didyoumeans[].val | tostring)
else empty
end
else
.[].pods[] |
{title: .title, text: [.subpods[].plaintext]} |
if .text[0] == "" then empty else . end |
(colors.bold + .title + ":" + colors.reset) ,
# pretty print this
# .text
( .text | " " + join("\n") | gsub("\n"; "\n ") | .), ""
# // jq -r ' .text | split("\n") | . as $array | [.[] | length] | max as $maxlength | $array[] | .' test.json
end