Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --ignore-subdirs flag to init command #435

Merged
merged 1 commit into from
Jun 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ loadBuildConfig menv mproject config stackRoot mresolver noConfigStrat = do
Nothing -> case noConfigStrat of
ThrowException -> do
currDir <- getWorkingDir
cabalFiles <- findCabalFiles currDir
cabalFiles <- findCabalFiles True currDir
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just passed in True here, can someone have a look if this might be problematic if init was called with the --ignore-subdirs flag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this looks completely correct to me.

throwM $ NoProjectConfigFound currDir
$ Just $ if null cabalFiles then "new" else "init"
ExecStrategy -> do
Expand Down
21 changes: 14 additions & 7 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import Stack.Solver
import Stack.Types
import System.Directory (getDirectoryContents)

findCabalFiles :: MonadIO m => Path Abs Dir -> m [Path Abs File]
findCabalFiles dir =
liftIO $ findFiles dir isCabal (not . isIgnored)
findCabalFiles :: MonadIO m => Bool -> Path Abs Dir -> m [Path Abs File]
findCabalFiles recurse dir =
liftIO $ findFiles dir isCabal (\subdir -> recurse && not (isIgnored subdir))
where
isCabal path = ".cabal" `isSuffixOf` toFilePath path

Expand All @@ -68,12 +68,12 @@ initProject initOpts = do
let dest = currDir </> stackDotYaml
dest' = toFilePath dest
exists <- fileExists dest
when ((not $ forceOverwrite initOpts) && exists) $
when (not (forceOverwrite initOpts) && exists) $
error ("Refusing to overwrite existing stack.yaml, " <>
"please delete before running stack init " <>
"or if you are sure use \"--force\"")

cabalfps <- findCabalFiles currDir
cabalfps <- findCabalFiles (includeSubDirs initOpts) currDir
$logInfo $ "Writing default config file to: " <> T.pack dest'
$logInfo $ "Basing on cabal files:"
mapM_ (\path -> $logInfo $ "- " <> T.pack (toFilePath path)) cabalfps
Expand Down Expand Up @@ -131,7 +131,7 @@ getDefaultResolver :: (MonadIO m, MonadMask m, MonadReader env m, HasConfig env,
-> [C.GenericPackageDescription] -- ^ cabal descriptions
-> InitOpts
-> m (Resolver, Map PackageName (Map FlagName Bool), Map PackageName Version)
getDefaultResolver cabalfps gpds initOpts = do
getDefaultResolver cabalfps gpds initOpts =
case ioMethod initOpts of
MethodSnapshot snapPref -> do
msnapshots <- getSnapshots'
Expand Down Expand Up @@ -199,6 +199,9 @@ data InitOpts = InitOpts
{ ioMethod :: !Method
-- ^ Preferred snapshots
, forceOverwrite :: Bool
-- ^ Force overwrite of existing stack.yaml
, includeSubDirs :: Bool
-- ^ If True, include all .cabal files found in any sub directories
}

data SnapPref = PrefNone | PrefLTS | PrefNightly
Expand All @@ -208,8 +211,12 @@ data Method = MethodSnapshot SnapPref | MethodResolver Resolver | MethodSolver

initOptsParser :: Parser InitOpts
initOptsParser =
InitOpts <$> method <*> overwrite
InitOpts <$> method <*> overwrite <*> fmap not ignoreSubDirs
where
ignoreSubDirs = flag False
True
(long "ignore-subdirs" <>
help "Do not search for .cabal files in sub directories")
overwrite = flag False
True
(long "force" <>
Expand Down