From 6290be859dc9641a7f83231778e786b60a8d0d2e Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 1 Oct 2024 19:54:32 +0200 Subject: Wrap common downloader fields into a record --- lib/SlackBuilder/Config.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/SlackBuilder/Config.hs b/lib/SlackBuilder/Config.hs index 995432f..88d2253 100644 --- a/lib/SlackBuilder/Config.hs +++ b/lib/SlackBuilder/Config.hs @@ -4,7 +4,8 @@ -- | Configuration file. module SlackBuilder.Config - ( Settings(..) + ( DownloaderSettings(..) + , Settings(..) , MaintainerSettings(..) , PackageSettings(..) , settingsCodec @@ -14,6 +15,7 @@ import Data.List.NonEmpty (NonEmpty(..)) import Data.Text (Text) import Toml ((.=)) import qualified Toml +import GHC.Records (HasField(..)) data Settings = Settings { ghToken :: !Text @@ -29,7 +31,7 @@ newtype MaintainerSettings = MaintainerSettings { signature :: Bool } deriving (Eq, Show) -data PackageSettings = PackageSettings +data DownloaderSettings = DownloaderSettings { name :: Text , template :: Text , is64 :: Bool @@ -40,6 +42,10 @@ data PackageSettings = PackageSettings , repackage :: Maybe [String] } deriving (Eq, Show) +newtype PackageSettings = PackageSettings + { downloader :: DownloaderSettings + } deriving (Eq, Show) + settingsCodec :: Toml.TomlCodec Settings settingsCodec = Settings <$> Toml.text "gh_token" .= ghToken @@ -54,8 +60,8 @@ maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings maintainerSettingsCodec = MaintainerSettings <$> Toml.bool "signature" .= signature -packageSettingsCodec :: Toml.TomlCodec PackageSettings -packageSettingsCodec = PackageSettings +downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings +downloaderSettingsCodec = DownloaderSettings <$> Toml.text "name" .= name <*> Toml.text "template" .= template <*> Toml.bool "is64" .= is64 @@ -68,3 +74,6 @@ packageSettingsCodec = PackageSettings githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name") packagistCodec = Toml.pair (Toml.text "owner") (Toml.text "name") textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker") + +packageSettingsCodec :: Toml.TomlCodec PackageSettings +packageSettingsCodec = Toml.dimap (getField @"downloader") PackageSettings downloaderSettingsCodec -- cgit v1.2.3