From 5f2b74d4e17d8b95a49dd091385d75797d669480 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 9 Jun 2015 18:36:23 +0300 Subject: [PATCH] Basic init command #229 --- src/Stack/Config.hs | 1 + src/Stack/Types/Config.hs | 5 +++++ src/main/Main.hs | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index 60a2df2d07..16d4a15bd7 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -222,6 +222,7 @@ loadConfig configArgs = do { lcConfig = config , lcLoadBuildConfig = loadBuildConfig mproject config , lcProjectRoot = fmap (\(_, fp, _) -> parent fp) mproject + , lcStackYaml = fmap (\(_, fp, _) -> fp) mproject } -- | Load the build configuration, adds build-specific values to config loaded by @loadConfig@. diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 6b1f21b471..f452d17fa5 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -176,6 +176,11 @@ data LoadConfig m = LoadConfig -- ^ Action to load the remaining 'BuildConfig'. , lcProjectRoot :: !(Maybe (Path Abs Dir)) -- ^ The project root directory, if in a project. + + , lcStackYaml :: !(Maybe (Path Abs File)) + -- ^ The project config file, if in a project. Note: If the STACK_YAML + -- environment variable is used, this may not simply be lcProjectRoot + -- with stack.yaml appended. } data NoBuildConfigStrategy diff --git a/src/main/Main.hs b/src/main/Main.hs index 824e864a35..ac0a727b2d 100644 --- a/src/main/Main.hs +++ b/src/main/Main.hs @@ -72,6 +72,10 @@ main = "Build the project(s) in this directory/configuration" (buildCmd DoNothing) buildOpts + addCommand "init" + "Create a missing stack.yaml file" + initCmd + (pure ()) addCommand "test" "Build and test the project(s) in this directory/configuration" (buildCmd DoTests) @@ -323,6 +327,23 @@ buildCmd :: FinalAction -> BuildOpts -> GlobalOpts -> IO () buildCmd finalAction opts go@GlobalOpts{..} = withBuildConfig go CreateConfig $ Stack.Build.build opts { boptsFinalAction = finalAction } +-- | Create a stack.yaml file, if missing +initCmd :: () -> GlobalOpts -> IO () +initCmd () go@GlobalOpts{..} = do + (manager,lc) <- loadConfigWithOpts go + runStackLoggingT manager globalLogLevel $ + Docker.rerunWithOptionalContainer (lcConfig lc) (lcProjectRoot lc) $ + runStackLoggingT manager globalLogLevel $ + case lcStackYaml lc of + Just file -> $logInfo $ + "stack.yaml already exists at: " <> + T.pack (toFilePath file) + Nothing -> do + bconfig <- lcLoadBuildConfig lc CreateConfig + $logInfo $ + "Project configuration file created at: " <> + T.pack (toFilePath $ bcStackYaml bconfig) + -- | Unpack packages to the filesystem unpackCmd :: [String] -> GlobalOpts -> IO () unpackCmd names go@GlobalOpts{..} = do