diff options
author | Ian Jeffries <ianspiral@gmail.com> | 2019-03-26 09:45:25 -0400 |
---|---|---|
committer | Alexey Kiryushin <alexey.a.kiryushin@gmail.com> | 2019-03-26 16:45:25 +0300 |
commit | 3bff037c1f36078c8543983e0d87731e8d073bc4 (patch) | |
tree | 5f086c038468074ff07c1d1fd8d3af3143e7294c /app | |
parent | 08ec8a00a18f8f900dac9be472501021d118f1d8 (diff) |
Allow specifying both --packages and --package. (#31)
This can be useful if you've stored the dependencies of your application in one directory, but have your application in another directory.
Diffstat (limited to 'app')
-rw-r--r-- | app/Server.hs | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/app/Server.hs b/app/Server.hs index 2304f27..9544539 100644 --- a/app/Server.hs +++ b/app/Server.hs @@ -184,10 +184,12 @@ data ServerConfig = ServerConfig , configUseHoogleApi :: !Bool } deriving (Show, Eq) -data PackagesPath - = DirectoryWithPackages FilePath - | Directories [FilePath] - deriving (Show, Eq) +data PackagesPath = PackagesPath + { pathDirWithPackages :: !(Maybe FilePath) + -- ^ Path to a directory containing Cabal package subdirectories. + , pathPackages :: ![FilePath] + -- ^ Paths to Cabal packages. + } deriving (Show, Eq) data Store = CreateStore FilePath @@ -198,16 +200,14 @@ data Store configParser :: Parser ServerConfig configParser = ServerConfig <$> - ((DirectoryWithPackages <$> - strOption + parsePackagesPath + (strOption (long "packages" <> metavar "PATH" <> - help "Path to a directory with Cabal packages")) <|> - Directories <$> - some - (strOption + help "Path to a directory with Cabal packages")) + (some + (strOption (long "package" <> short 'p' <> metavar "PATH" <> - help "Path to a Cabal package (Default: '.')")) - <|> pure (Directories ["."])) <*> + help "Path to a Cabal package (defaults to '.' if 'packages' not provided either)"))) <*> (pure 8080 <|> option auto @@ -263,6 +263,11 @@ configParser = help "Use public Hoogle JSON API (https://github.com/ndmitchell/hoogle/blob/3dbf68bfd701f942d3af2e6debb74a0a78cd392e/docs/API.md#json-api) to get documentation for not indexed packages (disabled by default)") +parsePackagesPath :: Parser FilePath -> Parser [FilePath] -> Parser PackagesPath +parsePackagesPath parseDir parsePaths = + (PackagesPath <$> fmap Just parseDir <*> parsePaths) + <|> pure (PackagesPath Nothing ["."]) + -------------------------------------------------------------------------------- -- Loading packages -------------------------------------------------------------------------------- @@ -708,10 +713,14 @@ addExternalIdInfo packageId packageInfo = do findDirectories :: PackagesPath -> IO [FilePath] findDirectories p = - case p of - DirectoryWithPackages dir -> - find (depth ==? 0) (fileType ==? Directory &&? filePath /=? dir) dir - Directories dirs -> return dirs + fmap (pathPackages p <>) packagesInPackageDir + where + packagesInPackageDir :: IO [FilePath] + packagesInPackageDir = + case pathDirWithPackages p of + Nothing -> return [] + Just dir -> + find (depth ==? 0) (fileType ==? Directory &&? filePath /=? dir) dir loadPackages :: ServerConfig |