prepare to support full query expressions on command line

This commit is contained in:
Simon Michael 2012-05-16 08:31:06 +00:00
parent 88afea8c44
commit a628964016
4 changed files with 9 additions and 5 deletions

View File

@ -182,9 +182,9 @@ filterSpecFromOpts opts@ReportOpts{..} d = FilterSpec {
where (apats,dpats,mds) = parsePatternArgs patterns_
-- | Convert report options to a (new) query.
queryFromOpts :: ReportOpts -> Day -> Query
queryFromOpts :: ReportOpts -> Day -> (Query, [QueryOpt])
queryFromOpts opts@ReportOpts{..} d = -- strace $
And $
(And $
[Date $ dateSpanFromOpts d opts]
++ (if null apats then [] else [Or $ map Acct apats])
++ (if null dpats then [] else [Or $ map Desc dpats])
@ -193,9 +193,13 @@ queryFromOpts opts@ReportOpts{..} d = -- strace $
++ (if empty_ then [Empty True] else [])
++ (maybe [] ((:[]) . Status) (clearedValueFromOpts opts))
++ (maybe [] ((:[]) . Depth) depth_)
,[])
where
(apats,dpats,mds) = parsePatternArgs patterns_
-- queryFromOpts :: ReportOpts -> Day -> (Query, [QueryOpt])
-- queryFromOpts opts d = parseQuery d (unwords $ patterns_ opts)
-- | Gather filter pattern arguments into a list of account patterns and a
-- list of description patterns. We interpret pattern arguments as
-- follows: those prefixed with "desc:" are description patterns, all

View File

@ -27,7 +27,7 @@ balancesheet :: CliOpts -> Journal -> IO ()
balancesheet CliOpts{reportopts_=ropts} j = do
-- let lines = case formatFromOpts ropts of Left err, Right ...
d <- getCurrentDay
let m = queryFromOpts (withoutBeginDate ropts) d
let (m,_) = queryFromOpts (withoutBeginDate ropts) d
assetreport@(_,assets) = accountsReport2 ropts (And [m, journalAssetAccountQuery j]) j
liabilityreport@(_,liabilities) = accountsReport2 ropts (And [m, journalLiabilityAccountQuery j]) j
equityreport@(_,equity) = accountsReport2 ropts (And [m, journalEquityAccountQuery j]) j

View File

@ -30,7 +30,7 @@ cashflow :: CliOpts -> Journal -> IO ()
cashflow CliOpts{reportopts_=ropts} j = do
-- let lines = case formatFromOpts ropts of Left err, Right ...
d <- getCurrentDay
let m = queryFromOpts (withoutBeginDate ropts) d
let (m,_) = queryFromOpts (withoutBeginDate ropts) d
cashreport@(_,total) = accountsReport2 ropts (And [m, journalCashAccountQuery j]) j
-- operatingreport@(_,operating) = accountsReport2 ropts (And [m, journalOperatingAccountMatcher j]) j
-- investingreport@(_,investing) = accountsReport2 ropts (And [m, journalInvestingAccountMatcher j]) j

View File

@ -22,7 +22,7 @@ import Hledger.Cli.Balance
incomestatement :: CliOpts -> Journal -> IO ()
incomestatement CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let m = queryFromOpts ropts d
let (m,_) = queryFromOpts ropts d
incomereport@(_,income) = accountsReport2 ropts (And [m, journalIncomeAccountQuery j]) j
expensereport@(_,expenses) = accountsReport2 ropts (And [m, journalExpenseAccountQuery j]) j
total = income + expenses