mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 12:24:43 +03:00
the --format option shall be known as "line format"
This commit is contained in:
parent
7f6cf1f849
commit
301f506486
@ -284,7 +284,7 @@ balance :: CliOpts -> Journal -> IO ()
|
||||
balance CliOpts{reportopts_=ropts} j = do
|
||||
d <- getCurrentDay
|
||||
let output =
|
||||
case formatFromOpts ropts of
|
||||
case lineFormatFromOpts ropts of
|
||||
Left err -> [err]
|
||||
Right _ ->
|
||||
case (intervalFromOpts ropts, balancetype_ ropts) of
|
||||
@ -298,7 +298,7 @@ balance CliOpts{reportopts_=ropts} j = do
|
||||
balanceReportAsText :: ReportOpts -> BalanceReport -> [String]
|
||||
balanceReportAsText opts ((items, total)) = concat lines ++ t
|
||||
where
|
||||
lines = case formatFromOpts opts of
|
||||
lines = case lineFormatFromOpts opts of
|
||||
Right f -> map (balanceReportItemAsText opts f) items
|
||||
Left err -> [[err]]
|
||||
t = if no_total_ opts
|
||||
|
@ -38,7 +38,7 @@ balancesheetmode = (defCommandMode $ ["balancesheet"]++aliases) {
|
||||
-- | Print a simple balance sheet.
|
||||
balancesheet :: CliOpts -> Journal -> IO ()
|
||||
balancesheet CliOpts{reportopts_=ropts} j = do
|
||||
-- let lines = case formatFromOpts ropts of Left err, Right ...
|
||||
-- let lines = case lineFormatFromOpts ropts of Left err, Right ...
|
||||
d <- getCurrentDay
|
||||
let q = queryFromOpts d (withoutBeginDate ropts)
|
||||
assetreport@(_,assets) = balanceReport ropts (And [q, journalAssetAccountQuery j]) j
|
||||
|
@ -40,7 +40,7 @@ cashflowmode = (defCommandMode ["cashflow","cf"]) {
|
||||
-- | Print a simple cashflow statement.
|
||||
cashflow :: CliOpts -> Journal -> IO ()
|
||||
cashflow CliOpts{reportopts_=ropts} j = do
|
||||
-- let lines = case formatFromOpts ropts of Left err, Right ...
|
||||
-- let lines = case lineFormatFromOpts ropts of Left err, Right ...
|
||||
d <- getCurrentDay
|
||||
let q = queryFromOpts d ropts
|
||||
cashreport@(_,total) = balanceReport ropts (And [q, journalCashAccountQuery j]) j
|
||||
|
@ -44,7 +44,7 @@ module Hledger.Cli.Options (
|
||||
defaultWidthWithFlag,
|
||||
widthFromOpts,
|
||||
-- | For balance:
|
||||
formatFromOpts,
|
||||
lineFormatFromOpts,
|
||||
|
||||
-- * Other utils
|
||||
hledgerAddons,
|
||||
@ -284,7 +284,7 @@ rawOptsToCliOpts rawopts = do
|
||||
-- | Do final validation of processed opts, raising an error if there is trouble.
|
||||
checkCliOpts :: CliOpts -> IO CliOpts -- or pure..
|
||||
checkCliOpts opts@CliOpts{reportopts_=ropts} = do
|
||||
case formatFromOpts ropts of
|
||||
case lineFormatFromOpts ropts of
|
||||
Left err -> optserror $ "could not parse format option: "++err
|
||||
Right _ -> return ()
|
||||
case widthFromOpts opts of
|
||||
@ -351,12 +351,12 @@ rulesFilePathFromOpts opts = do
|
||||
|
||||
-- | Parse the format option if provided, possibly returning an error,
|
||||
-- otherwise get the default value.
|
||||
formatFromOpts :: ReportOpts -> Either String [OutputFormat]
|
||||
formatFromOpts = maybe (Right defaultBalanceFormat) parseStringFormat . format_
|
||||
lineFormatFromOpts :: ReportOpts -> Either String [OutputFormat]
|
||||
lineFormatFromOpts = maybe (Right defaultBalanceLineFormat) parseStringFormat . format_
|
||||
|
||||
-- | Default line format for balance report: "%20(total) %2(depth_spacer)%-(account)"
|
||||
defaultBalanceFormat :: [OutputFormat]
|
||||
defaultBalanceFormat = [
|
||||
defaultBalanceLineFormat :: [OutputFormat]
|
||||
defaultBalanceLineFormat = [
|
||||
FormatField False (Just 20) Nothing TotalField
|
||||
, FormatLiteral " "
|
||||
, FormatField True (Just 2) Nothing DepthSpacerField
|
||||
|
Loading…
Reference in New Issue
Block a user