diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 0dc9981eb..ddaa1f9ad 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -9,11 +9,12 @@ tags. {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE NamedFieldPuns #-} module Hledger.Data.Transaction ( -- * Transaction nulltransaction, @@ -30,6 +31,7 @@ module Hledger.Data.Transaction ( balancedVirtualPostings, transactionsPostings, BalancingOpts(..), + HasBalancingOpts(..), defbalancingopts, isTransactionBalanced, balanceTransaction, @@ -660,6 +662,10 @@ transactionFile Transaction{tsourcepos} = GenericSourcePos f _ _ -> f JournalSourcePos f _ -> f +-- lenses + +makeHledgerClassyLenses ''BalancingOpts + -- tests tests_Transaction :: TestTree diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index edc0779ed..ba53adb4b 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -30,6 +30,7 @@ Some of these might belong in Hledger.Read.JournalReader or Hledger.Read. module Hledger.Read.Common ( Reader (..), InputOpts(..), + HasInputOpts(..), definputopts, rawOptsToInputOpts, rawOptsToCommodityStylesOpts, diff --git a/hledger-lib/Hledger/Read/InputOptions.hs b/hledger-lib/Hledger/Read/InputOptions.hs index 97398189f..09e55260d 100644 --- a/hledger-lib/Hledger/Read/InputOptions.hs +++ b/hledger-lib/Hledger/Read/InputOptions.hs @@ -4,10 +4,12 @@ Various options to use when reading journal files. Similar to CliOptions.inputflags, simplifies the journal-reading functions. -} +{-# LANGUAGE TemplateHaskell #-} module Hledger.Read.InputOptions ( -- * Types and helpers for input options InputOpts(..) +, HasInputOpts(..) , definputopts , forecastPeriod ) where @@ -16,10 +18,10 @@ import Control.Applicative ((<|>)) import Data.Time (Day, addDays) import Hledger.Data.Types -import Hledger.Data.Transaction (BalancingOpts(..), defbalancingopts) +import Hledger.Data.Transaction (BalancingOpts(..), HasBalancingOpts(..), defbalancingopts) import Hledger.Data.Journal (journalEndDate) import Hledger.Data.Dates (nulldatespan) -import Hledger.Utils +import Hledger.Utils (dbg2, makeHledgerClassyLenses) data InputOpts = InputOpts { -- files_ :: [FilePath] @@ -73,3 +75,10 @@ forecastPeriod d iopts j = do mjournalend = dbg2 "journalEndDate" $ journalEndDate False j -- ignore secondary dates DateSpan reportStart reportEnd = reportspan_ iopts return . dbg2 "forecastspan" $ DateSpan forecastStart forecastEnd + +-- ** Lenses + +makeHledgerClassyLenses ''InputOpts + +instance HasBalancingOpts InputOpts where + balancingOpts = balancingopts