module Settings ( Settings, readSettings, ) where import Data.Aeson qualified as A import Data.Yaml (decodeFileThrow) import GHC.Generics (Generic) import Git qualified 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")) <$> Git.getRootDir ]