summaryrefslogtreecommitdiff
path: root/lib/SlackBuilder/Config.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-10-01 19:54:32 +0200
committerEugen Wissner <belka@caraus.de>2024-10-01 19:54:32 +0200
commit6290be859dc9641a7f83231778e786b60a8d0d2e (patch)
tree0571b18cade4594f521fceca77240d7366fe816c /lib/SlackBuilder/Config.hs
parentf395d57b33b0fbf36c40358fb00b29ea3f96aea0 (diff)
downloadslackbuilder-6290be859dc9641a7f83231778e786b60a8d0d2e.tar.gz
Wrap common downloader fields into a record
Diffstat (limited to 'lib/SlackBuilder/Config.hs')
-rw-r--r--lib/SlackBuilder/Config.hs17
1 files changed, 13 insertions, 4 deletions
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