lib: Minor refactor.
This commit is contained in:
parent
765fb732c9
commit
c96947284e
@ -509,8 +509,7 @@ latestMaybeDate' = maximumByDef Nothing compareNothingMax
|
|||||||
|
|
||||||
-- | The depth limit this query specifies, or a large number if none.
|
-- | The depth limit this query specifies, or a large number if none.
|
||||||
queryDepth :: Query -> Int
|
queryDepth :: Query -> Int
|
||||||
queryDepth q = case queryDepth' q of [] -> 99999
|
queryDepth = minimumDef maxBound . queryDepth'
|
||||||
ds -> minimum ds
|
|
||||||
where
|
where
|
||||||
queryDepth' (Depth d) = [d]
|
queryDepth' (Depth d) = [d]
|
||||||
queryDepth' (Or qs) = concatMap queryDepth' qs
|
queryDepth' (Or qs) = concatMap queryDepth' qs
|
||||||
|
|||||||
@ -442,33 +442,27 @@ journalSelectingAmountFromOpts opts =
|
|||||||
|
|
||||||
-- | Convert report options and arguments to a query.
|
-- | Convert report options and arguments to a query.
|
||||||
queryFromOpts :: Day -> ReportOpts -> Query
|
queryFromOpts :: Day -> ReportOpts -> Query
|
||||||
queryFromOpts d ReportOpts{..} = simplifyQuery $ And $ [flagsq, argsq]
|
queryFromOpts d ropts = simplifyQuery . And $ [flagsq, argsq]
|
||||||
where
|
where
|
||||||
flagsq = And $
|
flagsq = queryFromOptsOnly d ropts
|
||||||
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
|
argsq = fst $ parseQuery d (T.pack $ query_ ropts)
|
||||||
++ (if real_ then [Real True] else [])
|
|
||||||
++ (if empty_ then [Empty True] else []) -- ?
|
|
||||||
++ [Or $ map StatusQ statuses_]
|
|
||||||
++ (maybe [] ((:[]) . Depth) depth_)
|
|
||||||
argsq = fst $ parseQuery d (T.pack query_)
|
|
||||||
|
|
||||||
-- | Convert report options to a query, ignoring any non-flag command line arguments.
|
-- | Convert report options to a query, ignoring any non-flag command line arguments.
|
||||||
queryFromOptsOnly :: Day -> ReportOpts -> Query
|
queryFromOptsOnly :: Day -> ReportOpts -> Query
|
||||||
queryFromOptsOnly _d ReportOpts{..} = simplifyQuery flagsq
|
queryFromOptsOnly _d ReportOpts{..} = simplifyQuery $ And flagsq
|
||||||
where
|
where
|
||||||
flagsq = And $
|
flagsq = consIf Real real_
|
||||||
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
|
. consIf Empty empty_
|
||||||
++ (if real_ then [Real True] else [])
|
. consJust Depth depth_
|
||||||
++ (if empty_ then [Empty True] else []) -- ?
|
$ [ (if date2_ then Date2 else Date) $ periodAsDateSpan period_
|
||||||
++ [Or $ map StatusQ statuses_]
|
, Or $ map StatusQ statuses_
|
||||||
++ (maybe [] ((:[]) . Depth) depth_)
|
]
|
||||||
|
consIf f b = if b then (f True:) else id
|
||||||
|
consJust f = maybe id ((:) . f)
|
||||||
|
|
||||||
-- | Convert report options and arguments to query options.
|
-- | Convert report options and arguments to query options.
|
||||||
queryOptsFromOpts :: Day -> ReportOpts -> [QueryOpt]
|
queryOptsFromOpts :: Day -> ReportOpts -> [QueryOpt]
|
||||||
queryOptsFromOpts d ReportOpts{..} = flagsqopts ++ argsqopts
|
queryOptsFromOpts d = snd . parseQuery d . T.pack . query_
|
||||||
where
|
|
||||||
flagsqopts = []
|
|
||||||
argsqopts = snd $ parseQuery d (T.pack query_)
|
|
||||||
|
|
||||||
-- Report dates.
|
-- Report dates.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user