-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
list
command (undocumented for now)
- Loading branch information
Showing
1 changed file
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
module Main (main) where | ||
|
||
import System.Environment | ||
|
||
import qualified Hpack | ||
import qualified Hpack.Config as Hpack | ||
import Hpack.Config | ||
import Control.Exception | ||
|
||
main :: IO () | ||
main = getArgs >>= Hpack.getOptions Hpack.packageConfig >>= mapM_ (uncurry Hpack.hpack) | ||
main = getArgs >>= \ case | ||
["list"] -> exposedModules packageConfig >>= mapM_ (putStrLn . unModule) | ||
args -> Hpack.getOptions packageConfig args >>= mapM_ (uncurry Hpack.hpack) | ||
|
||
exposedModules :: FilePath -> IO [Module] | ||
exposedModules file = readPackageConfig defaultDecodeOptions {decodeOptionsTarget = file} >>= \ case | ||
Left err -> throwIO $ ErrorCall err | ||
Right result -> return $ modules result | ||
where | ||
modules :: DecodeResult -> [Module] | ||
modules = maybe [] (libraryExposedModules . sectionData) . packageLibrary . decodeResultPackage |