2019-10-22 21:25:04 +03:00
|
|
|
module Config where
|
|
|
|
|
|
|
|
import UrbitPrelude
|
|
|
|
|
2019-12-17 17:31:50 +03:00
|
|
|
{-
|
|
|
|
All the configuration data revolving around a ship and the current
|
|
|
|
execution options.
|
|
|
|
-}
|
2019-10-22 21:25:04 +03:00
|
|
|
data PierConfig = PierConfig
|
2019-12-17 17:31:50 +03:00
|
|
|
{ _pcPierPath :: FilePath
|
|
|
|
, _pcDryRun :: Bool
|
|
|
|
} deriving (Show)
|
|
|
|
|
|
|
|
makeLenses ''PierConfig
|
2019-10-22 21:25:04 +03:00
|
|
|
|
|
|
|
class HasPierConfig env where
|
|
|
|
pierConfigL :: Lens' env PierConfig
|
|
|
|
|
2019-12-17 17:31:50 +03:00
|
|
|
pierPathL ∷ HasPierConfig a => Lens' a FilePath
|
|
|
|
pierPathL = pierConfigL . pcPierPath
|
2019-10-22 21:25:04 +03:00
|
|
|
|
2019-12-17 17:31:50 +03:00
|
|
|
dryRunL :: HasPierConfig a => Lens' a Bool
|
|
|
|
dryRunL = pierConfigL . pcDryRun
|
2019-10-22 21:25:04 +03:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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
|