aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorBrad Richardson <brichardson@structint.com>2020-03-30 16:39:07 -0500
committerBrad Richardson <brichardson@structint.com>2020-03-30 16:39:07 -0500
commit8b5aebc74fde829c7c22203b96d592f8e67b9272 (patch)
tree6e1c1270c3e951779c68530873040049b697bea1 /app
parentd0f51b8cb936e550110e44b0dcde4ac4c0f3a282 (diff)
downloadfpm-8b5aebc74fde829c7c22203b96d592f8e67b9272.tar.gz
fpm-8b5aebc74fde829c7c22203b96d592f8e67b9272.zip
Split settings into two stages
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs62
1 files changed, 39 insertions, 23 deletions
diff --git a/app/Main.hs b/app/Main.hs
index a6f3ea2..a80e8f7 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -32,11 +32,17 @@ import qualified Toml
newtype Arguments = Arguments { command' :: Command }
-data Settings = Settings {
- settingsCompiler :: !Text
- , settingsProjectName :: !Text
- , settingsDebugOptions :: ![Text]
- , settingsLibrary :: !Library }
+data TomlSettings = TomlSettings {
+ tomlSettingsCompiler :: !Text
+ , tomlSettingsProjectName :: !Text
+ , tomlSettingsDebugOptions :: ![Text]
+ , tomlSettingsLibrary :: !Library }
+
+data AppSettings = AppSettings {
+ appSettingsCompiler :: !Text
+ , appSettingsProjectName :: !Text
+ , appSettingsDebugOptions :: ![Text]
+ , appSettingsLibrary :: !Library }
data Library = Library { librarySourceDir :: !Text }
@@ -46,25 +52,26 @@ main :: IO ()
main = do
args <- getArguments
fpmContents <- TIO.readFile "fpm.toml"
- let settings = Toml.decode settingsCodec fpmContents
- case settings of
- Left err -> print err
- Right settings -> do
- app args settings
-
-app :: Arguments -> Settings -> IO ()
+ let tomlSettings = Toml.decode settingsCodec fpmContents
+ case tomlSettings of
+ Left err -> print err
+ Right tomlSettings' -> do
+ appSettings <- toml2AppSettings tomlSettings'
+ app args appSettings
+
+app :: Arguments -> AppSettings -> IO ()
app args settings = case command' args of
Run -> putStrLn "Run"
Test -> putStrLn "Test"
Build -> build settings
-build :: Settings -> IO ()
+build :: AppSettings -> IO ()
build settings = do
putStrLn "Building"
- let compiler = unpack $ settingsCompiler settings
- let projectName = unpack $ settingsProjectName settings
- let flags = map unpack $ settingsDebugOptions settings
- let librarySettings = settingsLibrary settings
+ let compiler = unpack $ appSettingsCompiler settings
+ let projectName = unpack $ appSettingsProjectName settings
+ let flags = map unpack $ appSettingsDebugOptions settings
+ let librarySettings = appSettingsLibrary settings
let librarySourceDir' = unpack $ librarySourceDir librarySettings
buildLibrary librarySourceDir'
[".f90", ".f", ".F", ".F90", ".f95", ".f03"]
@@ -113,17 +120,26 @@ getDirectoriesFiles dirs exts = getDirectoryFilesIO "" newPatterns
newPatterns = concatMap appendExts dirs
appendExts dir = map ((dir <//> "*") ++) exts
-settingsCodec :: TomlCodec Settings
+settingsCodec :: TomlCodec TomlSettings
settingsCodec =
- Settings
+ TomlSettings
<$> Toml.text "compiler"
- .= settingsCompiler
+ .= tomlSettingsCompiler
<*> Toml.text "name"
- .= settingsProjectName
+ .= tomlSettingsProjectName
<*> Toml.arrayOf Toml._Text "debug-options"
- .= settingsDebugOptions
+ .= tomlSettingsDebugOptions
<*> Toml.table libraryCodec "library"
- .= settingsLibrary
+ .= tomlSettingsLibrary
libraryCodec :: TomlCodec Library
libraryCodec = Library <$> Toml.text "source-dir" .= librarySourceDir
+
+toml2AppSettings :: TomlSettings -> IO AppSettings
+toml2AppSettings tomlSettings = do
+ return AppSettings
+ { appSettingsCompiler = tomlSettingsCompiler tomlSettings
+ , appSettingsProjectName = tomlSettingsProjectName tomlSettings
+ , appSettingsDebugOptions = tomlSettingsDebugOptions tomlSettings
+ , appSettingsLibrary = tomlSettingsLibrary tomlSettings
+ }