print, reg, balcmds: show json output pretty-printed
This commit is contained in:
		
							parent
							
								
									d963944c99
								
							
						
					
					
						commit
						d1f62f0f2e
					
				| @ -254,7 +254,6 @@ module Hledger.Cli.Commands.Balance ( | ||||
| ) where | ||||
| 
 | ||||
| import Data.Aeson (toJSON) | ||||
| import Data.Aeson.Text (encodeToLazyText) | ||||
| import Data.List | ||||
| import Data.Maybe | ||||
| --import qualified Data.Map as Map | ||||
| @ -321,7 +320,7 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do | ||||
|                 assrt          = not $ ignore_assertions_ $ inputopts_ opts | ||||
|             render = case fmt of | ||||
|               "txt"  -> budgetReportAsText ropts | ||||
|               "json" -> (++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON | ||||
|               "json" -> (++"\n") . TL.unpack . jsonPrettyText . toJSON | ||||
|               _      -> const $ error' $ unsupportedOutputFormatError fmt | ||||
|         writeOutput opts $ render budgetreport | ||||
| 
 | ||||
| @ -332,7 +331,7 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do | ||||
|                 "txt"  -> multiBalanceReportAsText ropts | ||||
|                 "csv"  -> (++"\n") . printCSV . multiBalanceReportAsCsv ropts | ||||
|                 "html" -> (++"\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts | ||||
|                 "json" -> (++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON | ||||
|                 "json" -> (++"\n") . TL.unpack . jsonPrettyText . toJSON | ||||
|                 _      -> const $ error' $ unsupportedOutputFormatError fmt | ||||
|           writeOutput opts $ render report | ||||
| 
 | ||||
| @ -347,7 +346,7 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do | ||||
|               render = case fmt of | ||||
|                 "txt"  -> balanceReportAsText | ||||
|                 "csv"  -> \ropts r -> (++ "\n") $ printCSV $ balanceReportAsCsv ropts r | ||||
|                 "json" -> const $ (++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON | ||||
|                 "json" -> const $ (++"\n") . TL.unpack . jsonPrettyText . toJSON | ||||
|                 _      -> const $ error' $ unsupportedOutputFormatError fmt | ||||
|           writeOutput opts $ render ropts report | ||||
| 
 | ||||
|  | ||||
| @ -16,11 +16,10 @@ module Hledger.Cli.Commands.Print ( | ||||
| where | ||||
| 
 | ||||
| import Data.Aeson (toJSON) | ||||
| import Data.Aeson.Text (encodeToLazyText) | ||||
| import Data.Maybe (isJust) | ||||
| import Data.Text (Text) | ||||
| import qualified Data.Text as T | ||||
| import qualified Data.Text.Lazy as T (toStrict) | ||||
| import qualified Data.Text.Lazy as TL | ||||
| import System.Console.CmdArgs.Explicit | ||||
| import Hledger.Read.CsvReader (CSV, printCSV) | ||||
| 
 | ||||
| @ -61,7 +60,7 @@ printEntries opts@CliOpts{reportopts_=ropts} j = do | ||||
|       render = case fmt of | ||||
|         "txt"  -> entriesReportAsText opts | ||||
|         "csv"  -> (++"\n") . printCSV . entriesReportAsCsv | ||||
|         "json" -> (++"\n") . T.unpack . T.toStrict . encodeToLazyText . toJSON | ||||
|         "json" -> (++"\n") . TL.unpack . jsonPrettyText . toJSON | ||||
|         _      -> const $ error' $ unsupportedOutputFormatError fmt | ||||
|   writeOutput opts $ render $ entriesReport ropts q j | ||||
| 
 | ||||
|  | ||||
| @ -19,7 +19,6 @@ module Hledger.Cli.Commands.Register ( | ||||
| ) where | ||||
| 
 | ||||
| import Data.Aeson (toJSON) | ||||
| import Data.Aeson.Text (encodeToLazyText) | ||||
| import Data.List | ||||
| import Data.Maybe | ||||
| -- import Data.Text (Text) | ||||
| @ -65,7 +64,7 @@ register opts@CliOpts{reportopts_=ropts} j = do | ||||
|   let fmt = outputFormatFromOpts opts | ||||
|       render | fmt=="txt"  = postingsReportAsText | ||||
|              | fmt=="csv"  = const ((++"\n") . printCSV . postingsReportAsCsv) | ||||
|              | fmt=="json" = const ((++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON) | ||||
|              | fmt=="json" = const ((++"\n") . TL.unpack . jsonPrettyText . toJSON) | ||||
|              | otherwise   = const $ error' $ unsupportedOutputFormatError fmt | ||||
|   writeOutput opts $ render opts $ postingsReport ropts (queryFromOpts d ropts) j | ||||
| 
 | ||||
|  | ||||
| @ -14,7 +14,6 @@ module Hledger.Cli.CompoundBalanceCommand ( | ||||
| ) where | ||||
| 
 | ||||
| import Data.Aeson (toJSON) | ||||
| import Data.Aeson.Text (encodeToLazyText) | ||||
| import Data.List (foldl') | ||||
| import Data.Maybe | ||||
| import qualified Data.Text as TS | ||||
| @ -241,7 +240,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r | ||||
|         "txt"  -> compoundBalanceReportAsText ropts' cbr | ||||
|         "csv"  -> printCSV (compoundBalanceReportAsCsv ropts cbr) ++ "\n" | ||||
|         "html" -> (++"\n") $ TL.unpack $ L.renderText $ compoundBalanceReportAsHtml ropts cbr | ||||
|         "json" -> (++"\n") $ TS.unpack $ TL.toStrict $ encodeToLazyText $ toJSON cbr | ||||
|         "json" -> (++"\n") $ TL.unpack $ jsonPrettyText $ toJSON cbr | ||||
|         _      -> error' $ unsupportedOutputFormatError fmt | ||||
| 
 | ||||
| -- | Summarise one or more (inclusive) end dates, in a way that's | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user