lib, cli: -U/-P/-C flags can be combined (#564)
This commit is contained in:
parent
44c6b324ab
commit
7fc921db86
@ -34,6 +34,7 @@ import Data.Data (Data)
|
|||||||
#if !MIN_VERSION_base(4,8,0)
|
#if !MIN_VERSION_base(4,8,0)
|
||||||
import Data.Functor.Compat ((<$>))
|
import Data.Functor.Compat ((<$>))
|
||||||
#endif
|
#endif
|
||||||
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Typeable (Typeable)
|
import Data.Typeable (Typeable)
|
||||||
@ -73,7 +74,7 @@ instance Default AccountListMode where def = ALDefault
|
|||||||
data ReportOpts = ReportOpts {
|
data ReportOpts = ReportOpts {
|
||||||
period_ :: Period
|
period_ :: Period
|
||||||
,interval_ :: Interval
|
,interval_ :: Interval
|
||||||
,clearedstatus_ :: Maybe ClearedStatus
|
,clearedstatus_ :: [ClearedStatus] -- ^ Zero, one, or two statuses to be matched
|
||||||
,cost_ :: Bool
|
,cost_ :: Bool
|
||||||
,depth_ :: Maybe Int
|
,depth_ :: Maybe Int
|
||||||
,display_ :: Maybe DisplayExp
|
,display_ :: Maybe DisplayExp
|
||||||
@ -262,16 +263,18 @@ intervalFromRawOpts = lastDef NoInterval . catMaybes . map intervalfromrawopt
|
|||||||
| n == "yearly" = Just $ Years 1
|
| n == "yearly" = Just $ Years 1
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
-- | Get the cleared status, if any, specified by the last of -C/--cleared,
|
-- | Get any cleared statuses to be matched, as specified by -C/--cleared,
|
||||||
-- --pending, -U/--uncleared options.
|
-- -P/--pending, -U/--uncleared options. -UPC is equivalent to no flags,
|
||||||
clearedStatusFromRawOpts :: RawOpts -> Maybe ClearedStatus
|
-- so this returns a list of 0-2 unique statuses.
|
||||||
clearedStatusFromRawOpts = lastMay . catMaybes . map clearedstatusfromrawopt
|
clearedStatusFromRawOpts :: RawOpts -> [ClearedStatus]
|
||||||
|
clearedStatusFromRawOpts = simplify . nub . sort . catMaybes . map clearedstatusfromrawopt
|
||||||
where
|
where
|
||||||
clearedstatusfromrawopt (n,_)
|
clearedstatusfromrawopt (n,_)
|
||||||
| n == "cleared" = Just Cleared
|
| n == "cleared" = Just Cleared
|
||||||
| n == "pending" = Just Pending
|
| n == "pending" = Just Pending
|
||||||
| n == "uncleared" = Just Uncleared
|
| n == "uncleared" = Just Uncleared
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
simplify l = if length l == 3 then [] else l -- TODO: (maxBound :: ClearedStatus) or something
|
||||||
|
|
||||||
type DisplayExp = String
|
type DisplayExp = String
|
||||||
|
|
||||||
@ -319,7 +322,7 @@ queryFromOpts d ReportOpts{..} = simplifyQuery $ And $ [flagsq, argsq]
|
|||||||
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
|
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
|
||||||
++ (if real_ then [Real True] else [])
|
++ (if real_ then [Real True] else [])
|
||||||
++ (if empty_ then [Empty True] else []) -- ?
|
++ (if empty_ then [Empty True] else []) -- ?
|
||||||
++ (maybe [] ((:[]) . Status) clearedstatus_)
|
++ [Or $ map Status clearedstatus_]
|
||||||
++ (maybe [] ((:[]) . Depth) depth_)
|
++ (maybe [] ((:[]) . Depth) depth_)
|
||||||
argsq = fst $ parseQuery d (T.pack query_)
|
argsq = fst $ parseQuery d (T.pack query_)
|
||||||
|
|
||||||
@ -331,7 +334,7 @@ queryFromOptsOnly _d ReportOpts{..} = simplifyQuery flagsq
|
|||||||
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
|
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
|
||||||
++ (if real_ then [Real True] else [])
|
++ (if real_ then [Real True] else [])
|
||||||
++ (if empty_ then [Empty True] else []) -- ?
|
++ (if empty_ then [Empty True] else []) -- ?
|
||||||
++ (maybe [] ((:[]) . Status) clearedstatus_)
|
++ [Or $ map Status clearedstatus_]
|
||||||
++ (maybe [] ((:[]) . Depth) depth_)
|
++ (maybe [] ((:[]) . Depth) depth_)
|
||||||
|
|
||||||
tests_queryFromOpts :: [Test]
|
tests_queryFromOpts :: [Test]
|
||||||
|
|||||||
@ -20,26 +20,21 @@ import Hledger.UI.UIOptions
|
|||||||
-- | Toggle between showing only cleared items or all items.
|
-- | Toggle between showing only cleared items or all items.
|
||||||
toggleCleared :: UIState -> UIState
|
toggleCleared :: UIState -> UIState
|
||||||
toggleCleared ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
toggleCleared ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
||||||
ui{aopts=uopts{cliopts_=copts{reportopts_=toggleCleared ropts}}}
|
ui{aopts=uopts{cliopts_=copts{reportopts_=reportOptsToggleStatus Cleared ropts}}}
|
||||||
where
|
|
||||||
toggleCleared ropts@ReportOpts{clearedstatus_=Just Cleared} = ropts{clearedstatus_=Nothing}
|
|
||||||
toggleCleared ropts = ropts{clearedstatus_=Just Cleared}
|
|
||||||
|
|
||||||
-- | Toggle between showing only pending items or all items.
|
-- | Toggle between showing only pending items or all items.
|
||||||
togglePending :: UIState -> UIState
|
togglePending :: UIState -> UIState
|
||||||
togglePending ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
togglePending ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
||||||
ui{aopts=uopts{cliopts_=copts{reportopts_=togglePending ropts}}}
|
ui{aopts=uopts{cliopts_=copts{reportopts_=reportOptsToggleStatus Pending ropts}}}
|
||||||
where
|
|
||||||
togglePending ropts@ReportOpts{clearedstatus_=Just Pending} = ropts{clearedstatus_=Nothing}
|
|
||||||
togglePending ropts = ropts{clearedstatus_=Just Pending}
|
|
||||||
|
|
||||||
-- | Toggle between showing only uncleared items or all items.
|
-- | Toggle between showing only uncleared items or all items.
|
||||||
toggleUncleared :: UIState -> UIState
|
toggleUncleared :: UIState -> UIState
|
||||||
toggleUncleared ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
toggleUncleared ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
||||||
ui{aopts=uopts{cliopts_=copts{reportopts_=toggleUncleared ropts}}}
|
ui{aopts=uopts{cliopts_=copts{reportopts_=reportOptsToggleStatus Uncleared ropts}}}
|
||||||
where
|
|
||||||
toggleUncleared ropts@ReportOpts{clearedstatus_=Just Uncleared} = ropts{clearedstatus_=Nothing}
|
reportOptsToggleStatus s ropts
|
||||||
toggleUncleared ropts = ropts{clearedstatus_=Just Uncleared}
|
| clearedstatus_ ropts == [s] = ropts{clearedstatus_=[]}
|
||||||
|
| otherwise = ropts{clearedstatus_=[s]}
|
||||||
|
|
||||||
-- | Toggle between showing all and showing only nonempty (more precisely, nonzero) items.
|
-- | Toggle between showing all and showing only nonempty (more precisely, nonzero) items.
|
||||||
toggleEmpty :: UIState -> UIState
|
toggleEmpty :: UIState -> UIState
|
||||||
@ -125,7 +120,7 @@ resetFilter ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=rop
|
|||||||
ui{aopts=uopts{cliopts_=copts{reportopts_=ropts{
|
ui{aopts=uopts{cliopts_=copts{reportopts_=ropts{
|
||||||
accountlistmode_=ALTree
|
accountlistmode_=ALTree
|
||||||
,empty_=True
|
,empty_=True
|
||||||
,clearedstatus_=Nothing
|
,clearedstatus_=[]
|
||||||
,real_=False
|
,real_=False
|
||||||
,query_=""
|
,query_=""
|
||||||
--,period_=PeriodAll
|
--,period_=PeriodAll
|
||||||
|
|||||||
@ -28,12 +28,11 @@ runHelp = runCommand "hledger-ui --help | less" >>= waitForProcess
|
|||||||
|
|
||||||
-- ui
|
-- ui
|
||||||
|
|
||||||
uiShowClearedStatus mc =
|
uiShowClearedStatus = map showstatus
|
||||||
case mc of
|
where
|
||||||
Just Cleared -> ["cleared"]
|
showstatus Cleared = "cleared"
|
||||||
Just Pending -> ["pending"]
|
showstatus Pending = "pending"
|
||||||
Just Uncleared -> ["uncleared"]
|
showstatus Uncleared = "uncleared"
|
||||||
Nothing -> []
|
|
||||||
|
|
||||||
-- | Draw the help dialog, called when help mode is active.
|
-- | Draw the help dialog, called when help mode is active.
|
||||||
helpDialog :: Widget Name
|
helpDialog :: Widget Name
|
||||||
|
|||||||
@ -55,11 +55,13 @@ hledger -fstatus.journal print --uncleared
|
|||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# 6. only one of these flags (the last) takes effect
|
# 6. these flags can be combined
|
||||||
hledger -fstatus.journal register --uncleared --pending --cleared
|
hledger -fstatus.journal register --uncleared --pending
|
||||||
>>>
|
>>>
|
||||||
2017/01/03 cleared (a) 1 1
|
2017/01/01 uncleared (a) 1 1
|
||||||
(b) 1 2
|
(b) 1 2
|
||||||
|
2017/01/02 pending (a) 1 3
|
||||||
|
(b) 1 4
|
||||||
>>>= 0
|
>>>= 0
|
||||||
|
|
||||||
# 7. these flags work with other commands
|
# 7. these flags work with other commands
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user