From fde13b66701956a53282f558d79a8ddbfca0c905 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Sat, 11 Apr 2020 15:26:40 -0500 Subject: Enable default settings for executables --- app/Main.hs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index b951ad8..66dedb8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -28,7 +28,9 @@ import Options.Applicative ( Parser , subparser , switch ) -import System.Directory ( doesDirectoryExist ) +import System.Directory ( doesDirectoryExist + , doesFileExist + ) import Toml ( TomlCodec , (.=) ) @@ -177,12 +179,14 @@ executableCodec = toml2AppSettings :: TomlSettings -> Bool -> IO AppSettings toml2AppSettings tomlSettings release = do + let projectName = tomlSettingsProjectName tomlSettings librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings executableSettings <- getExecutableSettings - $ tomlSettingsExecutables tomlSettings + (tomlSettingsExecutables tomlSettings) + projectName return AppSettings { appSettingsCompiler = tomlSettingsCompiler tomlSettings - , appSettingsProjectName = tomlSettingsProjectName tomlSettings + , appSettingsProjectName = projectName , appSettingsFlags = if release then [ "-Wall" @@ -221,6 +225,19 @@ getLibrarySettings maybeSettings = case maybeSettings of then return (Just (Library { librarySourceDir = "src" })) else return Nothing -getExecutableSettings :: [Executable] -> IO [Executable] -getExecutableSettings [] = undefined -getExecutableSettings executables = return executables +getExecutableSettings :: [Executable] -> Text -> IO [Executable] +getExecutableSettings [] projectName = do + defaultDirectoryExists <- doesDirectoryExist "app" + if defaultDirectoryExists + then do + defaultMainExists <- doesFileExist ("app" "main.f90") + if defaultMainExists + then return + [ Executable { executableSourceDir = "app" + , executableMainFile = "main.f90" + , executableName = projectName + } + ] + else return [] + else return [] +getExecutableSettings executables _ = return executables -- cgit v1.2.3