diff options
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"] + ] |