summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Conftrack.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Conftrack.hs b/src/Conftrack.hs
index b15fa02..ab830ff 100644
--- a/src/Conftrack.hs
+++ b/src/Conftrack.hs
@@ -16,6 +16,7 @@ module Conftrack
, readOptionalValue
, readRequiredValue
, readNested
+ , readNestedOptional
, SomeSource
, ConfigError(..)
, Key(..)
@@ -145,6 +146,17 @@ readNested (Key prefix') = Fetch $ \s1 -> do
(config, s2) <- nested (s1 { fetcherPrefix = fetcherPrefix s1 <> NonEmpty.toList prefix' })
pure (config, s2 { fetcherPrefix = fetcherPrefix s1 })
+readNestedOptional :: forall a. Config a => Key -> Fetch (Maybe a)
+readNestedOptional (Key prefix) = Fetch $ \s1 -> do
+ let (Fetch nested) = readConfig @a
+ (config, s2) <- nested (s1 { fetcherPrefix = fetcherPrefix s1 <> NonEmpty.toList prefix })
+
+ if null (fetcherErrors s2)
+ then pure (Just config, s2 { fetcherPrefix = fetcherPrefix s1 })
+ -- TODO: resetting errors like this makes configKeysOf less useful. Perhaps move nested errors to warnings?
+ else pure (Nothing, s2 { fetcherPrefix = fetcherPrefix s1
+ , fetcherErrors = fetcherErrors s1 })
+
collectUnused :: [SomeSource] -> IO [Warning]
collectUnused sources = do