diff options
Diffstat (limited to 'lib/SlackBuilder/Info.hs')
| -rw-r--r-- | lib/SlackBuilder/Info.hs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/SlackBuilder/Info.hs b/lib/SlackBuilder/Info.hs index e2f5018..59342cc 100644 --- a/lib/SlackBuilder/Info.hs +++ b/lib/SlackBuilder/Info.hs @@ -7,6 +7,7 @@ module SlackBuilder.Info ( PackageInfo(..) , generate , parseInfoFile + , readInfoFile ) where import Control.Applicative (Alternative(..)) @@ -26,7 +27,7 @@ import Crypto.Hash (Digest, MD5, digestFromByteString) import Data.Void (Void) import Data.Word (Word8) import Numeric (readHex, showHex) -import Text.Megaparsec (Parsec, count, eof, takeWhile1P) +import Text.Megaparsec (Parsec, count, eof, parse, takeWhile1P) import Text.Megaparsec.Byte (space, string, hexDigitChar) import Text.URI ( URI(..) @@ -34,6 +35,14 @@ import Text.URI , render ) import qualified Data.Word8 as Word8 +import SlackBuilder.Trans + ( SlackBuilderT(..) + , SlackBuilderException(..) + , relativeToRepository + ) +import System.FilePath ((</>), (<.>)) +import Control.Monad.IO.Class (MonadIO(..)) +import Conduit (MonadThrow(throwM)) type GenParser = Parsec Void ByteString @@ -110,6 +119,17 @@ parseInfoFile = PackageInfo . Char8.unpack *> packageName <* "\"\n" +readInfoFile :: Text -> Text -> SlackBuilderT PackageInfo +readInfoFile category packageName' = do + let packageName'' = Text.unpack packageName' + + infoPath <- relativeToRepository + $ Text.unpack category </> packageName'' </> packageName'' <.> "info" + infoContents <- liftIO $ ByteString.readFile infoPath + + either (throwM . MalformedInfoFile) pure + $ parse parseInfoFile infoPath infoContents + generate :: PackageInfo -> Text generate pkg = Lazy.Text.toStrict $ Text.Builder.toLazyText builder where |
