+13
-2
cli/print.go
+13
-2
cli/print.go
···
6
6
"log"
7
7
"os"
8
8
9
+
"github.com/atscan/atr/repo"
9
10
jsoniter "github.com/json-iterator/go"
10
11
)
11
12
12
-
func Print(v interface{}) error {
13
+
type ObjectOutput struct {
14
+
Did string `json:"did"`
15
+
Rkey string `json:"rkey"`
16
+
Cid string `json:"cid"`
17
+
Body interface{} `json:"body"`
18
+
Match interface{} `json:"-"`
19
+
}
20
+
21
+
func Print(v interface{}, ri repo.RepoItem, rs repo.RepoSnapshot) error {
22
+
13
23
json, err := jsoniter.Marshal(v)
14
24
if err != nil {
15
25
log.Fatal(err)
···
22
32
return nil
23
33
}
24
34
25
-
func PrettyPrint(v interface{}, hg func(io.Writer, string)) error {
35
+
func PrettyPrint(v interface{}, ri repo.RepoItem, rs repo.RepoSnapshot, hg func(io.Writer, string)) error {
36
+
26
37
json, err := jsoniter.MarshalIndent(v, "", " ")
27
38
if err != nil {
28
39
log.Fatal(err)
+15
-7
cmd/atr-show.go
+15
-7
cmd/atr-show.go
···
99
99
continue
100
100
}
101
101
}
102
-
var out interface{}
102
+
103
+
out := cli.ObjectOutput{Did: ss.Repo.SignedCommit().Did, Cid: e.Cid.String(), Rkey: e.Path, Body: e.Body}
104
+
103
105
if q != "" || qq != "" {
104
-
json, err := jsoniter.Marshal(e.Body)
106
+
json, err := jsoniter.Marshal(out)
105
107
if err != nil {
106
108
log.Fatal("jsoniter error:", err)
107
109
continue
···
126
128
if v == nil {
127
129
continue
128
130
}
129
-
out = v
131
+
out.Match = v
130
132
}
131
133
}
132
134
if qq != "" {
···
134
136
if err != nil {
135
137
log.Fatalln("jmespath error:", err)
136
138
}
137
-
out = r
139
+
out.Match = r
138
140
}
141
+
}
142
+
143
+
var ro interface{}
144
+
if out.Match != nil {
145
+
ro = out.Match
139
146
} else {
140
-
out = e.Body
147
+
ro = out
141
148
}
149
+
142
150
stat, _ := os.Stdout.Stat()
143
151
if !Raw && (stat.Mode()&os.ModeCharDevice) != 0 {
144
-
cli.PrettyPrint(out, hg)
152
+
cli.PrettyPrint(ro, e, ss, hg)
145
153
} else {
146
-
cli.Print(out)
154
+
cli.Print(ro, e, ss)
147
155
}
148
156
}
149
157
}