shrub/pkg/king/lib/Config.hs
Elliot Glaysher 8a09262092 Separate the config into pier and network sections.
Make the ames tests compile again, reading from a test instance of
HasNetworkConfig without phony HasPierConfig data.
2019-10-22 11:25:04 -07:00

51 lines
1.3 KiB
Haskell

module Config where
import UrbitPrelude
-- All the configuration data revolving around a ship and the current execution
-- options.
data PierConfig = PierConfig
{ pcPierPath :: FilePath
, pcDryRun :: Bool
} deriving (Show)
class HasPierConfig env where
pierConfigL :: Lens' env PierConfig
getPierPath :: (MonadReader env m, HasPierConfig env) => m FilePath
getPierPath = do
PierConfig{..} <- view pierConfigL
pure pcPierPath
getIsDryRun :: (MonadReader env m, HasPierConfig env) => m Bool
getIsDryRun = do
PierConfig{..} <- view pierConfigL
pure pcDryRun
-------------------------------------------------------------------------------
data NetworkingType
= NetworkNone
| NetworkNormal
| NetworkLocalhost
deriving (Show)
data NetworkConfig = NetworkConfig
{ ncNetworking :: NetworkingType
, ncAmesPort :: Maybe Word16
} deriving (Show)
class HasNetworkConfig env where
networkConfigL :: Lens' env NetworkConfig
getNetworkingType :: (MonadReader env m, HasNetworkConfig env)
=> m NetworkingType
getNetworkingType = do
NetworkConfig{..} <- view networkConfigL
pure ncNetworking
getAmesPort :: (MonadReader env m, HasNetworkConfig env) => m (Maybe Word16)
getAmesPort = do
NetworkConfig{..} <- view networkConfigL
pure ncAmesPort