updateReportSpecFromOpts -> updateReportSpec[With]
This commit is contained in:
		
							parent
							
								
									15dc638a07
								
							
						
					
					
						commit
						349ffd7c0b
					
				| @ -18,7 +18,8 @@ module Hledger.Reports.ReportOptions ( | |||||||
|   rawOptsToReportOpts, |   rawOptsToReportOpts, | ||||||
|   defreportspec, |   defreportspec, | ||||||
|   reportOptsToSpec, |   reportOptsToSpec, | ||||||
|   updateReportSpecFromOpts, |   updateReportSpec, | ||||||
|  |   updateReportSpecWith, | ||||||
|   rawOptsToReportSpec, |   rawOptsToReportSpec, | ||||||
|   flat_, |   flat_, | ||||||
|   tree_, |   tree_, | ||||||
| @ -245,12 +246,16 @@ reportOptsToSpec day ropts = do | |||||||
|       , rsQueryOpts = queryopts |       , rsQueryOpts = queryopts | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| -- | Regenerate a ReportSpec after updating ReportOpts, or return an error | -- | Update the ReportOpts and the fields derived from it in a ReportSpec, | ||||||
| -- message if there is a problem such as missing or unparseable options data. | -- or return an error message if there is a problem such as missing or  | ||||||
| -- This helps keep the ReportSpec, its underlying ReportOpts, and the ReportOpts' | -- unparseable options data. This is the safe way to change a ReportSpec,  | ||||||
| -- data fields like querystring_ all in sync. | -- ensuring that all fields (rsQuery, rsOpts, querystring_, etc.) are in sync. | ||||||
| updateReportSpecFromOpts :: (ReportOpts -> ReportOpts) -> ReportSpec -> Either String ReportSpec | updateReportSpec :: ReportOpts -> ReportSpec -> Either String ReportSpec | ||||||
| updateReportSpecFromOpts f rspec = reportOptsToSpec (rsToday rspec) . f $ rsOpts rspec | updateReportSpec ropts rspec = reportOptsToSpec (rsToday rspec) ropts | ||||||
|  | 
 | ||||||
|  | -- | Like updateReportSpec, but takes a ReportOpts-modifying function. | ||||||
|  | updateReportSpecWith :: (ReportOpts -> ReportOpts) -> ReportSpec -> Either String ReportSpec | ||||||
|  | updateReportSpecWith f rspec = reportOptsToSpec (rsToday rspec) . f $ rsOpts rspec | ||||||
| 
 | 
 | ||||||
| -- | Generate a ReportSpec from RawOpts and the current date. | -- | Generate a ReportSpec from RawOpts and the current date. | ||||||
| rawOptsToReportSpec :: RawOpts -> IO ReportSpec | rawOptsToReportSpec :: RawOpts -> IO ReportSpec | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ uiShowStatus copts ss = | |||||||
| reportSpecToggleStatusSomehow :: Status -> CliOpts -> ReportSpec -> ReportSpec | reportSpecToggleStatusSomehow :: Status -> CliOpts -> ReportSpec -> ReportSpec | ||||||
| reportSpecToggleStatusSomehow s copts = | reportSpecToggleStatusSomehow s copts = | ||||||
|     either (error "reportSpecToggleStatusSomehow: updating Status should not result in an error") id  -- PARTIAL: |     either (error "reportSpecToggleStatusSomehow: updating Status should not result in an error") id  -- PARTIAL: | ||||||
|     . updateReportSpecFromOpts update |     . updateReportSpecWith update | ||||||
|   where |   where | ||||||
|     update = case maybeposintopt "status-toggles" $ rawopts_ copts of |     update = case maybeposintopt "status-toggles" $ rawopts_ copts of | ||||||
|       Just 2 -> reportOptsToggleStatus2 s |       Just 2 -> reportOptsToggleStatus2 s | ||||||
| @ -189,7 +189,7 @@ toggleReal ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspe | |||||||
|     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} |     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} | ||||||
|   where |   where | ||||||
|     update = either (error "toggleReal: updating Real should not result in an error") id  -- PARTIAL: |     update = either (error "toggleReal: updating Real should not result in an error") id  -- PARTIAL: | ||||||
|            . updateReportSpecFromOpts (\ropts -> ropts{real_=not $ real_ ropts}) |            . updateReportSpecWith (\ropts -> ropts{real_=not $ real_ ropts}) | ||||||
| 
 | 
 | ||||||
| -- | Toggle the ignoring of balance assertions. | -- | Toggle the ignoring of balance assertions. | ||||||
| toggleIgnoreBalanceAssertions :: UIState -> UIState | toggleIgnoreBalanceAssertions :: UIState -> UIState | ||||||
| @ -237,14 +237,14 @@ updateReportPeriod updatePeriod ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@Cli | |||||||
|     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} |     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} | ||||||
|   where |   where | ||||||
|     update = either (error "updateReportPeriod: updating period should not result in an error") id  -- PARTIAL: |     update = either (error "updateReportPeriod: updating period should not result in an error") id  -- PARTIAL: | ||||||
|            . updateReportSpecFromOpts (\ropts -> ropts{period_=updatePeriod $ period_ ropts}) |            . updateReportSpecWith (\ropts -> ropts{period_=updatePeriod $ period_ ropts}) | ||||||
| 
 | 
 | ||||||
| -- | Apply a new filter query. | -- | Apply a new filter query. | ||||||
| setFilter :: String -> UIState -> UIState | setFilter :: String -> UIState -> UIState | ||||||
| setFilter s ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}} = | setFilter s ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}} = | ||||||
|     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} |     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} | ||||||
|   where |   where | ||||||
|     update = either (const rspec) id . updateReportSpecFromOpts (\ropts -> ropts{querystring_=querystring}) |     update = either (const rspec) id . updateReportSpecWith (\ropts -> ropts{querystring_=querystring}) | ||||||
|     querystring = words'' prefixes $ T.pack s |     querystring = words'' prefixes $ T.pack s | ||||||
| 
 | 
 | ||||||
| -- | Reset some filters & toggles. | -- | Reset some filters & toggles. | ||||||
| @ -303,7 +303,7 @@ updateReportDepth updateDepth ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOp | |||||||
|     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} |     ui{aopts=uopts{cliopts_=copts{reportspec_=update rspec}}} | ||||||
|   where |   where | ||||||
|     update = either (error "updateReportDepth: updating depth should not result in an error") id  -- PARTIAL: |     update = either (error "updateReportDepth: updating depth should not result in an error") id  -- PARTIAL: | ||||||
|            . updateReportSpecFromOpts (\ropts -> ropts{depth_=updateDepth (depth_ ropts) >>= clipDepth ropts}) |            . updateReportSpecWith (\ropts -> ropts{depth_=updateDepth (depth_ ropts) >>= clipDepth ropts}) | ||||||
|     clipDepth ropts d | d < 0            = depth_ ropts |     clipDepth ropts d | d < 0            = depth_ ropts | ||||||
|                       | d >= maxDepth ui = Nothing |                       | d >= maxDepth ui = Nothing | ||||||
|                       | otherwise        = Just d |                       | otherwise        = Just d | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ check copts@CliOpts{rawopts_} j = do | |||||||
|     args = listofstringopt "args" rawopts_ |     args = listofstringopt "args" rawopts_ | ||||||
|     -- reset the report spec that was generated by argsToCliOpts, |     -- reset the report spec that was generated by argsToCliOpts, | ||||||
|     -- since we are not using arguments as a query in the usual way |     -- since we are not using arguments as a query in the usual way | ||||||
|     copts' = cliOptsUpdateReportSpec (\ropts -> ropts{querystring_=[]}) copts |     copts' = cliOptsUpdateReportSpecWith (\ropts -> ropts{querystring_=[]}) copts | ||||||
| 
 | 
 | ||||||
|   case partitionEithers (map parseCheckArgument args) of |   case partitionEithers (map parseCheckArgument args) of | ||||||
|     (unknowns@(_:_), _) -> error' $ "These checks are unknown: "++unwords unknowns |     (unknowns@(_:_), _) -> error' $ "These checks are unknown: "++unwords unknowns | ||||||
| @ -81,8 +81,8 @@ runCheck copts@CliOpts{rawopts_} j (check,args) = | |||||||
| -- underlying report options with the given update function. | -- underlying report options with the given update function. | ||||||
| -- This can raise an error if there is a problem eg due to missing or | -- This can raise an error if there is a problem eg due to missing or | ||||||
| -- unparseable options data. See also updateReportSpecFromOpts. | -- unparseable options data. See also updateReportSpecFromOpts. | ||||||
| cliOptsUpdateReportSpec :: (ReportOpts -> ReportOpts) -> CliOpts -> CliOpts | cliOptsUpdateReportSpecWith :: (ReportOpts -> ReportOpts) -> CliOpts -> CliOpts | ||||||
| cliOptsUpdateReportSpec roptsupdate copts@CliOpts{reportspec_} = | cliOptsUpdateReportSpecWith roptsupdate copts@CliOpts{reportspec_} = | ||||||
|   case updateReportSpecFromOpts roptsupdate reportspec_ of |   case updateReportSpecWith roptsupdate reportspec_ of | ||||||
|     Left e   -> error' e  -- PARTIAL: |     Left e   -> error' e  -- PARTIAL: | ||||||
|     Right rs -> copts{reportspec_=rs} |     Right rs -> copts{reportspec_=rs} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user