mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-10 05:39:31 +03:00
print,reg,balcmds: fix JSON output, which wasn't JSON (#689)
This commit is contained in:
parent
40c296a446
commit
5f1a864c20
@ -254,6 +254,7 @@ 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
|
||||
@ -319,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") . pshow . toJSON -- XXX pshow for pretty output, but it may generate some junk
|
||||
"json" -> (++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render budgetreport
|
||||
|
||||
@ -330,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") . pshow . toJSON -- XXX pshow for pretty output, but it may generate some junk
|
||||
"json" -> (++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render report
|
||||
|
||||
@ -345,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") . pshow . toJSON -- XXX pshow for pretty output, but it may generate some junk
|
||||
"json" -> const $ (++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render ropts report
|
||||
|
||||
|
@ -16,9 +16,11 @@ 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 System.Console.CmdArgs.Explicit
|
||||
import Hledger.Read.CsvReader (CSV, printCSV)
|
||||
|
||||
@ -57,7 +59,7 @@ printEntries opts@CliOpts{reportopts_=ropts} j = do
|
||||
render = case fmt of
|
||||
"txt" -> entriesReportAsText opts
|
||||
"csv" -> (++"\n") . printCSV . entriesReportAsCsv
|
||||
"json" -> (++"\n") . pshow . toJSON -- XXX pshow for pretty output, but it may generate some junk
|
||||
"json" -> (++"\n") . T.unpack . T.toStrict . encodeToLazyText . toJSON
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render $ entriesReport ropts q j
|
||||
|
||||
|
@ -19,10 +19,12 @@ 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)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Lazy as TL
|
||||
import System.Console.CmdArgs.Explicit
|
||||
import Hledger.Read.CsvReader (CSV, CsvRecord, printCSV)
|
||||
|
||||
@ -61,7 +63,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") . pshow . toJSON) -- XXX pshow for pretty output, but it may generate some junk
|
||||
| fmt=="json" = const ((++"\n") . T.unpack . TL.toStrict . encodeToLazyText . toJSON)
|
||||
| otherwise = const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render opts $ postingsReport ropts (queryFromOpts d ropts) j
|
||||
|
||||
|
@ -14,6 +14,7 @@ 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
|
||||
@ -240,7 +241,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") $ pshow $ toJSON cbr -- XXX pshow for pretty output, but it may generate some junk
|
||||
"json" -> (++"\n") $ TS.unpack $ TL.toStrict $ encodeToLazyText $ 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