Skip to content

Commit

Permalink
Add list command (undocumented for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Sep 9, 2023
1 parent d9c187e commit ea22960
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions driver/Main.hs
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

0 comments on commit ea22960

Please sign in to comment.