mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-20 02:37:12 +03:00
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
|
||||
let budget = boolopt "budget" rawopts
|
||||
multiperiod = interval_ /= NoInterval
|
||||
format = outputFormatFromOpts opts
|
||||
fmt = outputFormatFromOpts opts
|
||||
|
||||
if budget then do -- single or multi period budget report
|
||||
reportspan <- reportSpan j ropts
|
||||
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j
|
||||
where
|
||||
assrt = not $ ignore_assertions_ $ inputopts_ opts
|
||||
render = case format of
|
||||
"csv" -> const $ error' "Sorry, CSV output is not yet implemented for this kind of report." -- TODO
|
||||
"html" -> const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
||||
_ -> budgetReportAsText ropts
|
||||
render = case fmt of
|
||||
"txt" -> budgetReportAsText ropts
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render budgetreport
|
||||
|
||||
else
|
||||
if multiperiod then do -- multi period balance report
|
||||
let report = multiBalanceReport ropts (queryFromOpts d ropts) j
|
||||
render = case format of
|
||||
render = case fmt of
|
||||
"txt" -> multiBalanceReportAsText ropts
|
||||
"csv" -> (++ "\n") . printCSV . multiBalanceReportAsCsv ropts
|
||||
"html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
|
||||
_ -> multiBalanceReportAsText ropts
|
||||
"html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render 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
|
||||
-- for historical balances we must use balanceReportFromMultiBalanceReport (also forces --no-elide)
|
||||
| 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
|
||||
"html" -> \_ _ -> error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
||||
_ -> balanceReportAsText
|
||||
_ -> const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render ropts report
|
||||
|
||||
-- rendering single-column balance reports
|
||||
|
@ -54,9 +54,9 @@ printEntries opts@CliOpts{reportopts_=ropts} j = do
|
||||
let q = queryFromOpts d ropts
|
||||
fmt = outputFormatFromOpts opts
|
||||
(render, ropts') = case fmt of
|
||||
"txt" -> (entriesReportAsText opts, ropts)
|
||||
"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
|
||||
_ -> (entriesReportAsText opts, ropts)
|
||||
_ -> (const $ error' $ unsupportedOutputFormatError fmt, ropts)
|
||||
writeOutput opts $ render $ entriesReport ropts' q j
|
||||
|
||||
entriesReportAsText :: CliOpts -> EntriesReport -> String
|
||||
|
@ -58,9 +58,9 @@ register :: CliOpts -> Journal -> IO ()
|
||||
register opts@CliOpts{reportopts_=ropts} j = do
|
||||
d <- getCurrentDay
|
||||
let fmt = outputFormatFromOpts opts
|
||||
render | fmt=="csv" = const ((++"\n") . printCSV . postingsReportAsCsv)
|
||||
| fmt=="html" = const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
||||
| otherwise = postingsReportAsText
|
||||
render | fmt=="txt" = postingsReportAsText
|
||||
| fmt=="csv" = const ((++"\n") . printCSV . postingsReportAsCsv)
|
||||
| otherwise = const $ error' $ unsupportedOutputFormatError fmt
|
||||
writeOutput opts $ render opts $ postingsReport ropts (queryFromOpts d ropts) j
|
||||
|
||||
postingsReportAsCsv :: PostingsReport -> CSV
|
||||
|
@ -26,7 +26,7 @@ import Text.Tabular as T
|
||||
import Hledger
|
||||
import Hledger.Cli.Commands.Balance
|
||||
import Hledger.Cli.CliOptions
|
||||
import Hledger.Cli.Utils (writeOutput)
|
||||
import Hledger.Cli.Utils (unsupportedOutputFormatError, writeOutput)
|
||||
|
||||
-- | Description of a compound balance report command,
|
||||
-- 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_
|
||||
}
|
||||
userq = queryFromOpts d ropts'
|
||||
format = outputFormatFromOpts opts
|
||||
fmt = outputFormatFromOpts opts
|
||||
|
||||
-- make a CompoundBalanceReport.
|
||||
-- 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
|
||||
writeOutput opts $
|
||||
case format of
|
||||
case fmt of
|
||||
"txt" -> compoundBalanceReportAsText ropts' cbr
|
||||
"csv" -> printCSV (compoundBalanceReportAsCsv ropts cbr) ++ "\n"
|
||||
"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
|
||||
-- visually different from showDateSpan, suggesting discrete end dates
|
||||
|
@ -10,6 +10,7 @@ Hledger.Utils.
|
||||
|
||||
module Hledger.Cli.Utils
|
||||
(
|
||||
unsupportedOutputFormatError,
|
||||
withJournalDo,
|
||||
writeOutput,
|
||||
journalTransform,
|
||||
@ -57,6 +58,10 @@ import Hledger.Read
|
||||
import Hledger.Reports
|
||||
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
|
||||
-- transformations according to options, and run a hledger command with it.
|
||||
-- Or, throw an error.
|
||||
|
Loading…
Reference in New Issue
Block a user