diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-23 09:55:28 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-11-07 09:50:52 +0100 |
commit | 1127c71fa5f5c5a3d6bfde818cb00eb26e9d4cb3 (patch) | |
tree | 003e76b6690461aff107999fcc4e1b54c6efb294 /app/Settings.hs | |
parent | 8c6ab0cbb68ef2deaf575b0eb341fd6c652e1848 (diff) |
add settings
Diffstat (limited to 'app/Settings.hs')
-rw-r--r-- | app/Settings.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/Settings.hs b/app/Settings.hs new file mode 100644 index 0000000..116a3d2 --- /dev/null +++ b/app/Settings.hs @@ -0,0 +1,43 @@ +module Settings + ( Settings, + readSettings, + ) +where + +import Data.Aeson qualified as A +import Data.Yaml (decodeFileThrow) +import GHC.Generics (Generic) +import System.Directory (doesFileExist) +import System.Environment.XDG.BaseDir (getSystemConfigFiles, getUserConfigFile) + +data Settings = Settings + { + } + deriving (Show, Generic) + +instance Semigroup Settings where + _ <> _ = Settings {} + +instance Monoid Settings where + mempty = Settings {} + +instance A.FromJSON Settings + +instance A.ToJSON Settings + +readSettings :: IO Settings +readSettings = + fmap mconcat + . mapM + ( \fp -> + doesFileExist fp >>= \case + True -> decodeFileThrow fp + False -> pure mempty + ) + =<< concat + <$> sequence + [ getSystemConfigFiles "anissue" "settings.yaml", + ((: []) <$> getUserConfigFile "anissue" "settings.yaml"), + -- TODO Read settings from Git base dir + pure ["./anissue.yaml"] + ] |