+4
Makefile
+4
Makefile
···
10
10
.PHONY: build
11
11
build: ## Build all executables
12
12
go build ./cmd/atr.go
13
+
b:
14
+
@make build
13
15
14
16
install: ## Install all executables
15
17
go install -ldflags "-X main._version=`git tag --sort=-version:refname | head -n 1`" ./cmd/atr.go
18
+
i:
19
+
@make install
16
20
17
21
.PHONY: fmt
18
22
fmt: ## Format all go files
+48
-16
cmd/atr.go
+48
-16
cmd/atr.go
···
23
23
"github.com/fatih/color"
24
24
"github.com/ipfs/go-cid"
25
25
"github.com/itchyny/gojq"
26
+
"github.com/jmespath/go-jmespath"
26
27
jsoniter "github.com/json-iterator/go"
27
28
"github.com/klauspost/compress/zstd"
28
29
"github.com/urfave/cli/v2"
···
112
113
&cli.StringFlag{
113
114
Name: "query",
114
115
Aliases: []string{"q"},
115
-
Usage: "Query results (jq syntax)",
116
+
Usage: "Query results (jq)",
117
+
Value: "",
118
+
},
119
+
&cli.StringFlag{
120
+
Name: "query-jmes",
121
+
Aliases: []string{"qq"},
122
+
Usage: "Query results (jmespath)",
116
123
Value: "",
117
124
},
118
125
&cli.BoolFlag{
···
134
141
query = tq
135
142
}
136
143
}
144
+
qq := ctx.String("query-jmes")
145
+
var queryJmes *jmespath.JMESPath
146
+
if qq != "" {
147
+
jc, err := jmespath.Compile(qq)
148
+
if err != nil {
149
+
return err
150
+
}
151
+
queryJmes = jc
152
+
}
137
153
138
154
eo, err := exec.Command("defaults", "read", "-g", "AppleInterfaceStyle").Output()
139
155
if err != nil {
···
155
171
}
156
172
}
157
173
var out interface{}
158
-
if q != "" {
174
+
if q != "" || qq != "" {
159
175
json, err := jsoniter.Marshal(e.Body)
160
176
if err != nil {
161
177
log.Fatal("jsoniter error:", err)
···
167
183
log.Fatal("jsoniter error:", err)
168
184
continue
169
185
}
170
-
iter := query.Run(interface{}(pv))
171
-
for {
172
-
v, ok := iter.Next()
173
-
if !ok {
174
-
break
175
-
}
176
-
if err, ok := v.(error); ok {
177
-
log.Fatalln("gojq iter error:", err)
178
-
continue
186
+
if q != "" {
187
+
iter := query.Run(interface{}(pv))
188
+
for {
189
+
v, ok := iter.Next()
190
+
if !ok {
191
+
break
192
+
}
193
+
if err, ok := v.(error); ok {
194
+
log.Fatalln("gojq iter error:", err)
195
+
continue
196
+
}
197
+
if v == nil {
198
+
continue
199
+
}
200
+
out = v
179
201
}
180
-
if v == nil {
181
-
continue
202
+
}
203
+
if qq != "" {
204
+
r, err := queryJmes.Search(pv)
205
+
if err != nil {
206
+
log.Fatalln("jmespath error:", err)
182
207
}
183
-
out = v
208
+
out = r
184
209
}
185
210
} else {
186
211
out = e.Body
···
322
347
if err != nil {
323
348
log.Fatal(err)
324
349
}
350
+
s := string(json)
351
+
if s == "null" {
352
+
return nil
353
+
}
325
354
fmt.Println(string(json))
326
355
return nil
327
356
}
···
331
360
if err != nil {
332
361
log.Fatal(err)
333
362
}
334
-
hg(os.Stdout, string(json))
335
-
fmt.Println("")
363
+
s := string(json)
364
+
if s == "null" {
365
+
return nil
366
+
}
367
+
hg(os.Stdout, s+"\n")
336
368
return nil
337
369
}
338
370
+4
go.mod
+4
go.mod
···
14
14
github.com/ipfs/go-ipld-cbor v0.0.7-0.20230126201833-a73d038d90bc
15
15
github.com/ipld/go-car/v2 v2.10.1
16
16
github.com/itchyny/gojq v0.12.13
17
+
github.com/jmespath/go-jmespath v0.4.0
17
18
github.com/json-iterator/go v1.1.12
18
19
github.com/klauspost/compress v1.16.7
19
20
github.com/urfave/cli/v2 v2.25.7
···
29
30
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
30
31
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
31
32
github.com/hashicorp/golang-lru v0.5.4 // indirect
33
+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
32
34
github.com/ipfs/bbloom v0.0.4 // indirect
33
35
github.com/ipfs/go-block-format v0.1.2 // indirect
34
36
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
···
58
60
github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect
59
61
github.com/russross/blackfriday/v2 v2.1.0 // indirect
60
62
github.com/spaolacci/murmur3 v1.1.0 // indirect
63
+
github.com/spf13/cobra v1.7.0 // indirect
64
+
github.com/spf13/pflag v1.0.5 // indirect
61
65
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect
62
66
github.com/x448/float16 v0.8.4 // indirect
63
67
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
+11
go.sum
+11
go.sum
···
40
40
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
41
41
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
42
42
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
43
+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
44
+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
43
45
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
44
46
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
45
47
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
···
87
89
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
88
90
github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o=
89
91
github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
92
+
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
93
+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
94
+
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
95
+
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
90
96
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
91
97
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
92
98
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
···
164
170
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
165
171
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
166
172
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
173
+
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
174
+
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
175
+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
176
+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
167
177
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
168
178
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
169
179
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
···
270
280
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
271
281
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
272
282
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
283
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
273
284
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
274
285
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
275
286
lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=