bs,cf,is,bal,print,reg: reject invalid output formats
This commit is contained in:
parent
7ec25da13a
commit
8b520b5c3e
@ -309,26 +309,26 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do
|
|||||||
Right _ -> do
|
Right _ -> do
|
||||||
let budget = boolopt "budget" rawopts
|
let budget = boolopt "budget" rawopts
|
||||||
multiperiod = interval_ /= NoInterval
|
multiperiod = interval_ /= NoInterval
|
||||||
format = outputFormatFromOpts opts
|
fmt = outputFormatFromOpts opts
|
||||||
|
|
||||||
if budget then do -- single or multi period budget report
|
if budget then do -- single or multi period budget report
|
||||||
reportspan <- reportSpan j ropts
|
reportspan <- reportSpan j ropts
|
||||||
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j
|
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j
|
||||||
where
|
where
|
||||||
assrt = not $ ignore_assertions_ $ inputopts_ opts
|
assrt = not $ ignore_assertions_ $ inputopts_ opts
|
||||||
render = case format of
|
render = case fmt of
|
||||||
"csv" -> const $ error' "Sorry, CSV output is not yet implemented for this kind of report." -- TODO
|
"txt" -> budgetReportAsText ropts
|
||||||
"html" -> const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||||
_ -> budgetReportAsText ropts
|
|
||||||
writeOutput opts $ render budgetreport
|
writeOutput opts $ render budgetreport
|
||||||
|
|
||||||
else
|
else
|
||||||
if multiperiod then do -- multi period balance report
|
if multiperiod then do -- multi period balance report
|
||||||
let report = multiBalanceReport ropts (queryFromOpts d ropts) j
|
let report = multiBalanceReport ropts (queryFromOpts d ropts) j
|
||||||
render = case format of
|
render = case fmt of
|
||||||
|
"txt" -> multiBalanceReportAsText ropts
|
||||||
"csv" -> (++ "\n") . printCSV . multiBalanceReportAsCsv ropts
|
"csv" -> (++ "\n") . printCSV . multiBalanceReportAsCsv ropts
|
||||||
"html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
|
"html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
|
||||||
_ -> multiBalanceReportAsText ropts
|
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||||
writeOutput opts $ render report
|
writeOutput opts $ render report
|
||||||
|
|
||||||
else do -- single period simple balance report
|
else do -- single period simple balance report
|
||||||
@ -339,10 +339,10 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do
|
|||||||
in balanceReportFromMultiBalanceReport ropts' (queryFromOpts d ropts) j
|
in balanceReportFromMultiBalanceReport ropts' (queryFromOpts d ropts) j
|
||||||
-- for historical balances we must use balanceReportFromMultiBalanceReport (also forces --no-elide)
|
-- for historical balances we must use balanceReportFromMultiBalanceReport (also forces --no-elide)
|
||||||
| otherwise = balanceReport ropts (queryFromOpts d ropts) j -- simple Ledger-style balance report
|
| otherwise = balanceReport ropts (queryFromOpts d ropts) j -- simple Ledger-style balance report
|
||||||
render = case format of
|
render = case fmt of
|
||||||
|
"txt" -> balanceReportAsText
|
||||||
"csv" -> \ropts r -> (++ "\n") $ printCSV $ balanceReportAsCsv ropts r
|
"csv" -> \ropts r -> (++ "\n") $ printCSV $ balanceReportAsCsv ropts r
|
||||||
"html" -> \_ _ -> error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||||
_ -> balanceReportAsText
|
|
||||||
writeOutput opts $ render ropts report
|
writeOutput opts $ render ropts report
|
||||||
|
|
||||||
-- rendering single-column balance reports
|
-- rendering single-column balance reports
|
||||||
|
|||||||
@ -54,9 +54,9 @@ printEntries opts@CliOpts{reportopts_=ropts} j = do
|
|||||||
let q = queryFromOpts d ropts
|
let q = queryFromOpts d ropts
|
||||||
fmt = outputFormatFromOpts opts
|
fmt = outputFormatFromOpts opts
|
||||||
(render, ropts') = case fmt of
|
(render, ropts') = case fmt of
|
||||||
|
"txt" -> (entriesReportAsText opts, ropts)
|
||||||
"csv" -> ((++"\n") . printCSV . entriesReportAsCsv, ropts{accountlistmode_=ALFlat})
|
"csv" -> ((++"\n") . printCSV . entriesReportAsCsv, ropts{accountlistmode_=ALFlat})
|
||||||
"html" -> (const $ error' "Sorry, HTML output is not yet implemented for this kind of report.", ropts{accountlistmode_=ALFlat}) -- TODO
|
_ -> (const $ error' $ unsupportedOutputFormatError fmt, ropts)
|
||||||
_ -> (entriesReportAsText opts, ropts)
|
|
||||||
writeOutput opts $ render $ entriesReport ropts' q j
|
writeOutput opts $ render $ entriesReport ropts' q j
|
||||||
|
|
||||||
entriesReportAsText :: CliOpts -> EntriesReport -> String
|
entriesReportAsText :: CliOpts -> EntriesReport -> String
|
||||||
|
|||||||
@ -58,9 +58,9 @@ register :: CliOpts -> Journal -> IO ()
|
|||||||
register opts@CliOpts{reportopts_=ropts} j = do
|
register opts@CliOpts{reportopts_=ropts} j = do
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
let fmt = outputFormatFromOpts opts
|
let fmt = outputFormatFromOpts opts
|
||||||
render | fmt=="csv" = const ((++"\n") . printCSV . postingsReportAsCsv)
|
render | fmt=="txt" = postingsReportAsText
|
||||||
| fmt=="html" = const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
| fmt=="csv" = const ((++"\n") . printCSV . postingsReportAsCsv)
|
||||||
| otherwise = postingsReportAsText
|
| otherwise = const $ error' $ unsupportedOutputFormatError fmt
|
||||||
writeOutput opts $ render opts $ postingsReport ropts (queryFromOpts d ropts) j
|
writeOutput opts $ render opts $ postingsReport ropts (queryFromOpts d ropts) j
|
||||||
|
|
||||||
postingsReportAsCsv :: PostingsReport -> CSV
|
postingsReportAsCsv :: PostingsReport -> CSV
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import Text.Tabular as T
|
|||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli.Commands.Balance
|
import Hledger.Cli.Commands.Balance
|
||||||
import Hledger.Cli.CliOptions
|
import Hledger.Cli.CliOptions
|
||||||
import Hledger.Cli.Utils (writeOutput)
|
import Hledger.Cli.Utils (unsupportedOutputFormatError, writeOutput)
|
||||||
|
|
||||||
-- | Description of a compound balance report command,
|
-- | Description of a compound balance report command,
|
||||||
-- from which we generate the command's cmdargs mode and IO action.
|
-- from which we generate the command's cmdargs mode and IO action.
|
||||||
@ -142,7 +142,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
|
|||||||
no_total_=if percent_ && length cbcqueries > 1 then True else no_total_
|
no_total_=if percent_ && length cbcqueries > 1 then True else no_total_
|
||||||
}
|
}
|
||||||
userq = queryFromOpts d ropts'
|
userq = queryFromOpts d ropts'
|
||||||
format = outputFormatFromOpts opts
|
fmt = outputFormatFromOpts opts
|
||||||
|
|
||||||
-- make a CompoundBalanceReport.
|
-- make a CompoundBalanceReport.
|
||||||
-- For efficiency, generate a price oracle here and reuse it with each subreport.
|
-- For efficiency, generate a price oracle here and reuse it with each subreport.
|
||||||
@ -235,10 +235,11 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
|
|||||||
|
|
||||||
-- render appropriately
|
-- render appropriately
|
||||||
writeOutput opts $
|
writeOutput opts $
|
||||||
case format of
|
case fmt of
|
||||||
|
"txt" -> compoundBalanceReportAsText ropts' cbr
|
||||||
"csv" -> printCSV (compoundBalanceReportAsCsv ropts cbr) ++ "\n"
|
"csv" -> printCSV (compoundBalanceReportAsCsv ropts cbr) ++ "\n"
|
||||||
"html" -> (++ "\n") $ TL.unpack $ L.renderText $ compoundBalanceReportAsHtml ropts cbr
|
"html" -> (++ "\n") $ TL.unpack $ L.renderText $ compoundBalanceReportAsHtml ropts cbr
|
||||||
_ -> compoundBalanceReportAsText ropts' cbr
|
_ -> error' $ unsupportedOutputFormatError fmt
|
||||||
|
|
||||||
-- | Summarise one or more (inclusive) end dates, in a way that's
|
-- | Summarise one or more (inclusive) end dates, in a way that's
|
||||||
-- visually different from showDateSpan, suggesting discrete end dates
|
-- visually different from showDateSpan, suggesting discrete end dates
|
||||||
|
|||||||
@ -10,6 +10,7 @@ Hledger.Utils.
|
|||||||
|
|
||||||
module Hledger.Cli.Utils
|
module Hledger.Cli.Utils
|
||||||
(
|
(
|
||||||
|
unsupportedOutputFormatError,
|
||||||
withJournalDo,
|
withJournalDo,
|
||||||
writeOutput,
|
writeOutput,
|
||||||
journalTransform,
|
journalTransform,
|
||||||
@ -57,6 +58,10 @@ import Hledger.Read
|
|||||||
import Hledger.Reports
|
import Hledger.Reports
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
|
|
||||||
|
-- | Standard error message for a bad output format specified with -O/-o.
|
||||||
|
unsupportedOutputFormatError :: String -> String
|
||||||
|
unsupportedOutputFormatError fmt = "Sorry, output format \""++fmt++"\" is unrecognised or not yet implemented for this report."
|
||||||
|
|
||||||
-- | Parse the user's specified journal file(s) as a Journal, maybe apply some
|
-- | Parse the user's specified journal file(s) as a Journal, maybe apply some
|
||||||
-- transformations according to options, and run a hledger command with it.
|
-- transformations according to options, and run a hledger command with it.
|
||||||
-- Or, throw an error.
|
-- Or, throw an error.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user