diff options
author | stuebinm | 2024-06-07 22:43:14 +0200 |
---|---|---|
committer | stuebinm | 2024-06-07 22:43:14 +0200 |
commit | d10c2f0dac08fb2cf0a7df2fb6a745a4759a73cf (patch) | |
tree | 87ee833ec98956ce66a111322587923ee994ea1d /src/Conftrack | |
parent | c1cf159fa67a107a395166c199c401aac0918c31 (diff) |
nested configs which are optional
Diffstat (limited to '')
-rw-r--r-- | src/Conftrack.hs | 12 |
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 |