@@ -397,6 +397,10 @@ part states:
397
397
Name : "oldest" ,
398
398
Usage : "sort by oldest first" ,
399
399
},
400
+ & cli.BoolFlag {
401
+ Name : "json" ,
402
+ Usage : "output deal info as json format" ,
403
+ },
400
404
},
401
405
Action : func (cctx * cli.Context ) error {
402
406
api , closer , err := NewMarketNode (cctx )
@@ -451,7 +455,7 @@ part states:
451
455
tm .Clear ()
452
456
tm .MoveCursor (1 , 1 )
453
457
454
- err = outputStorageDeals (tm .Output , deals , verbose )
458
+ err = outputStorageDeals (tm .Output , deals , verbose , cctx . Bool ( "json" ) )
455
459
if err != nil {
456
460
return err
457
461
}
@@ -477,7 +481,7 @@ part states:
477
481
}
478
482
}
479
483
480
- return outputStorageDeals (os .Stdout , deals , verbose )
484
+ return outputStorageDeals (os .Stdout , deals , verbose , cctx . Bool ( "json" ) )
481
485
},
482
486
}
483
487
@@ -635,6 +639,10 @@ var getDealCmd = &cli.Command{
635
639
Name : "proposal-cid" ,
636
640
Usage : "cid of deal proposal" ,
637
641
},
642
+ & cli.BoolFlag {
643
+ Name : "json" ,
644
+ Usage : "output deal info as json format" ,
645
+ },
638
646
},
639
647
Action : func (cliCtx * cli.Context ) error {
640
648
if ! cliCtx .IsSet ("deal-id" ) && ! cliCtx .IsSet ("proposal-cid" ) {
@@ -682,6 +690,15 @@ var getDealCmd = &cli.Command{
682
690
}
683
691
}
684
692
693
+ if cliCtx .Bool ("json" ) {
694
+ data , err := json .MarshalIndent (deal , "" , " " )
695
+ if err != nil {
696
+ return err
697
+ }
698
+ fmt .Println (string (data ))
699
+ return nil
700
+ }
701
+
685
702
return outputStorageDeal (deal )
686
703
},
687
704
}
@@ -743,11 +760,20 @@ func printStates(data interface{}) error {
743
760
return nil
744
761
}
745
762
746
- func outputStorageDeals (out io.Writer , deals []market.MinerDeal , verbose bool ) error {
763
+ func outputStorageDeals (out io.Writer , deals []market.MinerDeal , verbose bool , inJson bool ) error {
747
764
sort .Slice (deals , func (i , j int ) bool {
748
765
return deals [i ].CreationTime .Time ().Before (deals [j ].CreationTime .Time ())
749
766
})
750
767
768
+ if inJson {
769
+ data , err := json .MarshalIndent (deals , "" , " " )
770
+ if err != nil {
771
+ return err
772
+ }
773
+ _ , err = fmt .Fprintln (out , string (data ))
774
+ return err
775
+ }
776
+
751
777
w := tabwriter .NewWriter (out , 2 , 4 , 2 , ' ' , 0 )
752
778
753
779
if verbose {
0 commit comments