aboutsummaryrefslogtreecommitdiffstats
path: root/app/Settings.hs
blob: 2d3c2048a294fb2519b184ed365118a8596b63d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Settings
  ( Settings,
    readSettings,
  )
where

import Backend qualified
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)
import System.FilePath ((</>))

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"),
          ((: []) . (</> "anissue.yaml")) <$> Backend.getRootDir
        ]