Wrap common downloader fields into a record
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user