AT Protocol IPLD-CAR Repository toolkit (CLI)

show: better print

tree 605adefe ff7b9d42

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