Skip to content

Commit

Permalink
Basic init command #229
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jun 9, 2015
1 parent 527642d commit 5f2b74d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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@.
Expand Down
5 changes: 5 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f2b74d

Please sign in to comment.