6
6
"text/tabwriter"
7
7
8
8
bcli "github.com/filecoin-project/boost/cli"
9
+ "github.com/filecoin-project/boost/cmd"
9
10
lcli "github.com/filecoin-project/lotus/cli"
10
11
"github.com/filecoin-project/lotus/lib/tablewriter"
11
12
"github.com/ipfs/go-cid"
@@ -40,9 +41,18 @@ var piecesListPiecesCmd = &cli.Command{
40
41
return err
41
42
}
42
43
44
+ if cctx .Bool ("json" ) {
45
+
46
+ pieceCidsJson := map [string ]interface {}{
47
+ "pieceCids" : pieceCids ,
48
+ }
49
+ return cmd .PrintJson (pieceCidsJson )
50
+ }
51
+
43
52
for _ , pc := range pieceCids {
44
53
fmt .Println (pc )
45
54
}
55
+
46
56
return nil
47
57
},
48
58
}
@@ -69,6 +79,14 @@ var piecesListCidInfosCmd = &cli.Command{
69
79
return err
70
80
}
71
81
82
+ if cctx .Bool ("json" ) && ! cctx .Bool ("verbose" ) {
83
+ dataCidsJson := map [string ]interface {}{
84
+ "dataCids" : cids ,
85
+ }
86
+
87
+ return cmd .PrintJson (dataCidsJson )
88
+ }
89
+
72
90
w := tablewriter .New (tablewriter .Col ("CID" ),
73
91
tablewriter .Col ("Piece" ),
74
92
tablewriter .Col ("BlockOffset" ),
@@ -79,12 +97,18 @@ var piecesListCidInfosCmd = &cli.Command{
79
97
tablewriter .Col ("DealLen" ),
80
98
)
81
99
100
+ type dataCids map [string ]interface {}
101
+ var out []dataCids
102
+
82
103
for _ , c := range cids {
83
104
if ! cctx .Bool ("verbose" ) {
84
105
fmt .Println (c )
85
106
continue
86
107
}
87
108
109
+ type pbl map [string ]interface {}
110
+ var pbls []pbl
111
+
88
112
ci , err := nodeApi .PiecesGetCIDInfo (ctx , c )
89
113
if err != nil {
90
114
fmt .Printf ("Error getting CID info: %s\n " , err )
@@ -109,8 +133,34 @@ var piecesListCidInfosCmd = &cli.Command{
109
133
"DealOffset" : deal .Offset ,
110
134
"DealLen" : deal .Length ,
111
135
})
136
+
137
+ deal := map [string ]interface {}{
138
+ "ID" : deal .DealID ,
139
+ "Sector" : deal .SectorID ,
140
+ "Offset" : deal .Offset ,
141
+ "Length" : deal .Length ,
142
+ }
143
+ tpbl := pbl {
144
+ "PieceCid" : pi .PieceCID ,
145
+ "BlockOffset" : location .RelOffset ,
146
+ "BlockLength" : location .BlockSize ,
147
+ "Deal" : deal ,
148
+ }
149
+
150
+ pbls = append (pbls , tpbl )
112
151
}
113
152
}
153
+
154
+ tdataCids := dataCids {
155
+ "DataCid" : c ,
156
+ "PieceBlockLocation" : pbls ,
157
+ }
158
+
159
+ out = append (out , tdataCids )
160
+ }
161
+
162
+ if cctx .Bool ("json" ) && cctx .Bool ("verbose" ) {
163
+ return cmd .PrintJson (out )
114
164
}
115
165
116
166
if cctx .Bool ("verbose" ) {
@@ -146,6 +196,28 @@ var piecesInfoCmd = &cli.Command{
146
196
return err
147
197
}
148
198
199
+ if cctx .Bool ("json" ) {
200
+
201
+ type deal map [string ]interface {}
202
+ var deals []deal
203
+ for _ , d := range pi .Deals {
204
+ dl := deal {
205
+ "ID" : d .DealID ,
206
+ "SectorID" : d .SectorID ,
207
+ "Offset" : d .Offset ,
208
+ "Length" : d .Length ,
209
+ }
210
+ deals = append (deals , dl )
211
+ }
212
+
213
+ pieceinfo := map [string ]interface {}{
214
+ "PieceCid" : pi .PieceCID ,
215
+ "Deals" : deals ,
216
+ }
217
+
218
+ return cmd .PrintJson (pieceinfo )
219
+ }
220
+
149
221
fmt .Println ("Piece: " , pi .PieceCID )
150
222
w := tabwriter .NewWriter (os .Stdout , 4 , 4 , 2 , ' ' , 0 )
151
223
fmt .Fprintln (w , "Deals:\n DealID\t SectorID\t Length\t Offset" )
@@ -181,6 +253,31 @@ var piecesCidInfoCmd = &cli.Command{
181
253
return err
182
254
}
183
255
256
+ if cctx .Bool ("json" ) {
257
+
258
+ type pbl map [string ]interface {}
259
+ type bl map [string ]interface {}
260
+ var pbls []pbl
261
+ for _ , d := range ci .PieceBlockLocations {
262
+ tbp := bl {
263
+ "RelOffset" : d .RelOffset ,
264
+ "BlockSize" : d .BlockSize ,
265
+ }
266
+ tpbl := pbl {
267
+ "PieceCid" : d .PieceCID ,
268
+ "BlockLocation" : tbp ,
269
+ }
270
+ pbls = append (pbls , tpbl )
271
+ }
272
+
273
+ pieceinfo := map [string ]interface {}{
274
+ "DataCid" : ci .CID ,
275
+ "PieceBlockLocation" : pbls ,
276
+ }
277
+
278
+ return cmd .PrintJson (pieceinfo )
279
+ }
280
+
184
281
fmt .Println ("Info for: " , ci .CID )
185
282
186
283
w := tabwriter .NewWriter (os .Stdout , 4 , 4 , 2 , ' ' , 0 )
0 commit comments