2022-12-11 17:51:11 -05:00
|
|
|
module Internal.Config
|
|
|
|
( readConfig
|
|
|
|
, readYaml
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Control.Exception
|
2022-12-15 23:03:07 -05:00
|
|
|
-- import Control.Lens
|
2022-12-11 17:51:11 -05:00
|
|
|
|
2022-12-15 23:03:07 -05:00
|
|
|
-- import Data.Maybe
|
|
|
|
-- import qualified Data.Text as T
|
|
|
|
-- import Data.Typeable
|
|
|
|
-- import Data.Void
|
2022-12-11 17:51:11 -05:00
|
|
|
import Data.Yaml
|
|
|
|
|
|
|
|
import Dhall hiding (record)
|
2022-12-15 23:03:07 -05:00
|
|
|
-- import qualified Dhall.Core as DC
|
|
|
|
-- import qualified Dhall.Map as DM
|
|
|
|
-- import Dhall.Src
|
2022-12-11 17:51:11 -05:00
|
|
|
|
|
|
|
import Internal.Types
|
|
|
|
|
|
|
|
readConfig :: FilePath -> IO Config
|
|
|
|
readConfig confpath = do
|
2022-12-15 23:03:07 -05:00
|
|
|
-- let subs = DM.fromList typeSubs
|
|
|
|
-- let settings = over substitutions (DM.union subs) defaultEvaluateSettings
|
|
|
|
-- unfix <$> inputFileWithSettings settings auto confpath
|
|
|
|
unfix <$> inputFile auto confpath
|
2022-12-11 17:51:11 -05:00
|
|
|
|
2022-12-15 23:03:07 -05:00
|
|
|
-- typeSubs :: [(T.Text, DC.Expr Src Void)]
|
|
|
|
-- typeSubs = firstOrder ++ higherOrder
|
|
|
|
-- where
|
|
|
|
-- toVar a = fmap (\n -> (T.pack $ show n, maximum $ expected a))
|
|
|
|
-- $ listToMaybe $ snd $ splitTyConApp $ typeOf a
|
|
|
|
-- higherOrder =
|
|
|
|
-- [ ("ExpSplit", maximum $ expected (auto :: Decoder ExpSplit))
|
|
|
|
-- , ("ExpTx", maximum $ expected (auto :: Decoder ExpTx))
|
|
|
|
-- , ("SplitCur", maximum $ expected (auto :: Decoder SplitCur))
|
|
|
|
-- , ("SplitAcnt", maximum $ expected (auto :: Decoder SplitAcnt))
|
|
|
|
-- , ("CurID", maximum $ expected (auto :: Decoder CurID))
|
|
|
|
-- , ("AcntID", maximum $ expected (auto :: Decoder AcntID))
|
|
|
|
-- ]
|
|
|
|
-- firstOrder = catMaybes
|
|
|
|
-- [ toVar (auto :: Decoder TimeUnit)
|
|
|
|
-- , toVar (auto :: Decoder WeekdayPat)
|
|
|
|
-- , toVar (auto :: Decoder MDYPat)
|
|
|
|
-- , toVar (auto :: Decoder Gregorian)
|
|
|
|
-- , toVar (auto :: Decoder GregorianM)
|
|
|
|
-- , toVar (auto :: Decoder ModPat)
|
|
|
|
-- , toVar (auto :: Decoder CronPat)
|
|
|
|
-- , toVar (auto :: Decoder DatePat)
|
|
|
|
-- , toVar (auto :: Decoder Income)
|
|
|
|
-- , toVar (auto :: Decoder Tax)
|
|
|
|
-- , toVar (auto :: Decoder Bucket)
|
|
|
|
-- , toVar (auto :: Decoder TimeAmount)
|
|
|
|
-- , toVar (auto :: Decoder Expense)
|
|
|
|
-- , toVar (auto :: Decoder Decimal)
|
|
|
|
-- , toVar (auto :: Decoder Statement)
|
|
|
|
-- , toVar (auto :: Decoder Manual)
|
|
|
|
-- , toVar (auto :: Decoder TxOpts)
|
|
|
|
-- , toVar (auto :: Decoder ToTx)
|
|
|
|
-- , toVar (auto :: Decoder Match)
|
|
|
|
-- , toVar (auto :: Decoder MatchYMD)
|
|
|
|
-- , toVar (auto :: Decoder MatchVal)
|
|
|
|
-- , toVar (auto :: Decoder MatchDate)
|
|
|
|
-- , toVar (auto :: Decoder SplitNum)
|
|
|
|
-- , toVar (auto :: Decoder MatchDesc)
|
|
|
|
-- , toVar (auto :: Decoder MatchOther)
|
|
|
|
-- , toVar (auto :: Decoder SqlConfig)
|
|
|
|
-- ]
|
2022-12-11 17:51:11 -05:00
|
|
|
|
|
|
|
readYaml :: FromJSON a => FilePath -> IO a
|
|
|
|
readYaml p = do
|
|
|
|
r <- decodeFileEither p
|
|
|
|
case r of
|
|
|
|
Right a -> return a
|
|
|
|
Left e -> throw e
|