Skip to content

Commit

Permalink
Merge pull request #1780 from achernyak/stack-init
Browse files Browse the repository at this point in the history
Have "stack init" accept a list of sub-directories
  • Loading branch information
harendra-kumar committed Feb 11, 2016
2 parents 4fc1b8d + ea8e85b commit cee18eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
27 changes: 16 additions & 11 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import Control.Monad
import Control.Monad.Catch (MonadMask, throwM)
import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.Reader (asks, MonadReader)
import Control.Monad.Reader (MonadReader, asks)
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as L
import qualified Data.Foldable as F
import Data.Function (on)
import qualified Data.HashMap.Strict as HM
import qualified Data.IntMap as IntMap
import qualified Data.Foldable as F
import Data.List (intersect, maximumBy)
import Data.List.Extra (nubOrd)
import Data.Map (Map)
Expand All @@ -35,13 +35,13 @@ import Network.HTTP.Client.Conduit (HasHttpManager)
import Path
import Path.IO
import Stack.BuildPlan
import Stack.Config (getSnapshots,
makeConcreteResolver)
import Stack.Constants
import Stack.Solver
import Stack.Types
import Stack.Types.Internal ( HasTerminal, HasReExec
, HasLogLevel)
import Stack.Config ( getSnapshots
, makeConcreteResolver)
import Stack.Types.Internal (HasLogLevel, HasReExec,
HasTerminal)
import qualified System.FilePath as FP

-- | Generate stack.yaml
Expand All @@ -57,6 +57,7 @@ initProject
initProject currDir initOpts mresolver = do
let dest = currDir </> stackDotYaml

dirs <- mapM (resolveDir' . T.unpack) (searchDirs initOpts)
reldest <- toFilePath `liftM` makeRelativeToCurrentDir dest

exists <- doesFileExist dest
Expand All @@ -67,8 +68,10 @@ initProject currDir initOpts mresolver = do

let noPkgMsg = "In order to init, you should have an existing .cabal \
\file. Please try \"stack new\" instead."

cabalfps <- findCabalFiles (includeSubDirs initOpts) currDir
let findCabalFiles' = findCabalFiles (includeSubDirs initOpts)
cabalfps <- if null dirs
then findCabalFiles' currDir
else liftM concat $ mapM findCabalFiles' dirs
(bundle, dupPkgs) <- cabalPackagesCheck cabalfps noPkgMsg Nothing

(r, flags, extraDeps, rbundle) <- getDefaultResolver dest initOpts
Expand Down Expand Up @@ -435,12 +438,14 @@ getRecommendedSnapshots snapshots = do
]

data InitOpts = InitOpts
{ useSolver :: Bool
{ useSolver :: Bool
-- ^ Use solver to determine required external dependencies
, omitPackages :: Bool
, omitPackages :: Bool
-- ^ Exclude conflicting or incompatible user packages
, forceOverwrite :: Bool
-- ^ Overwrite existing stack.yaml
, includeSubDirs :: Bool
-- ^ If True, include all .cabal files found in any sub directories
, searchDirs :: ![T.Text]
-- ^ List of sub directories to search for .cabal files
}
44 changes: 25 additions & 19 deletions src/Stack/Options.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings,RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Stack.Options
(BuildCommand(..)
Expand Down Expand Up @@ -26,32 +27,32 @@ module Stack.Options
,globalOptsFromMonoid
) where

import Control.Monad.Logger (LogLevel(..))
import Data.Char (isSpace, toLower)
import Data.List (intercalate)
import Data.List.Split (splitOn)
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Control.Monad.Logger (LogLevel (..))
import Data.Char (isSpace, toLower)
import Data.List (intercalate)
import Data.List.Split (splitOn)
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Text.Read (decimal)
import Distribution.Version (anyVersion)
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Text.Read (decimal)
import Distribution.Version (anyVersion)
import Options.Applicative
import Options.Applicative.Args
import Options.Applicative.Builder.Extra
import Options.Applicative.Types (fromM, oneM, readerAsk)
import Stack.Clean (CleanOpts(..))
import Stack.Config (packagesParser)
import Options.Applicative.Types (fromM, oneM, readerAsk)
import Stack.Clean (CleanOpts (..))
import Stack.Config (packagesParser)
import Stack.ConfigCmd
import Stack.Constants (stackProgName)
import Stack.Coverage (HpcReportOpts(..))
import Stack.Constants (stackProgName)
import Stack.Coverage (HpcReportOpts (..))
import Stack.Docker
import qualified Stack.Docker as Docker
import qualified Stack.Docker as Docker
import Stack.Dot
import Stack.Ghci (GhciOpts(..))
import Stack.Ghci (GhciOpts (..))
import Stack.Init
import Stack.New
import Stack.Nix
Expand Down Expand Up @@ -682,7 +683,12 @@ initOptsParser :: Parser InitOpts
initOptsParser =
InitOpts <$> solver <*> omitPackages
<*> overwrite <*> fmap not ignoreSubDirs
<*> searchDirs
where
searchDirs =
many (textArgument
(metavar "DIRS" <>
help "Directories to include, default is current directory."))
ignoreSubDirs = switch (long "ignore-subdirs" <>
help "Do not search for .cabal files in sub directories")
overwrite = switch (long "force" <>
Expand Down

0 comments on commit cee18eb

Please sign in to comment.