forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-to-go-struct.sh
executable file
·46 lines (37 loc) · 1.13 KB
/
json-to-go-struct.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
#!/bin/bash
# Dependency: requires json-to-go-cli, jq
# Install with npm: `npm i json-to-go-cli -g`
# Install with brew: `brew install jq`
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title JSON to Go Struct
# @raycast.mode fullOutput
# @raycast.packageName Developer Utilities
# Optional parameters:
# @raycast.argument1 {"type": "text", "placeholder": "inline", "optional": true}
# @raycast.icon images/go.png
# Documentation:
# @raycast.author tiancheng92
# @raycast.authorURL https://github.com/tiancheng92
# @raycast.description Convert the copied JSON into a golang structure.
if ! command -v json-to-go &> /dev/null; then
echo "trans command is required (https://github.com/mholt/json-to-go).";
exit 1;
fi
if ! command -v jq &> /dev/null; then
echo "jq command is required (https://stedolan.github.io/jq/).";
exit 1;
fi
echo "$(pbpaste)" | jq &> /dev/null
if [ $(echo $?) != 0 ]; then
echo "json parse error";
echo "raw data: $(pbpaste)"
exit 1;
fi
if [ "$1" != "" ]; then
json-to-go -s "$(pbpaste)" -i
json-to-go -s "$(pbpaste)" -i | pbcopy
else
json-to-go -s "$(pbpaste)"
json-to-go -s "$(pbpaste)" | pbcopy
fi