|
| 1 | +{-# LANGUAGE DataKinds #-} |
| 2 | +{-# LANGUAGE DeriveGeneric #-} |
| 3 | +{-# LANGUAGE FlexibleInstances #-} |
| 4 | +{-# LANGUAGE OverloadedStrings #-} |
| 5 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 6 | +{-# LANGUAGE TypeApplications #-} |
| 7 | +{-# LANGUAGE TypeSynonymInstances #-} |
| 8 | + |
| 9 | +module App.Commands.CreateIndex |
| 10 | + ( cmdCreateIndex |
| 11 | + ) where |
| 12 | + |
| 13 | +import Control.Lens |
| 14 | +import Control.Monad |
| 15 | +import Data.Generics.Product.Any |
| 16 | +import Data.Semigroup ((<>)) |
| 17 | +import HaskellWorks.Data.Xml.Succinct.Cursor.MMap |
| 18 | +import Options.Applicative hiding (columns) |
| 19 | + |
| 20 | +import qualified App.Commands.Types as Z |
| 21 | +import qualified Data.ByteString.Lazy as LBS |
| 22 | +import qualified HaskellWorks.Data.ByteString.Lazy as LBS |
| 23 | + |
| 24 | +runCreateIndex :: Z.CreateIndexOptions -> IO () |
| 25 | +runCreateIndex opt = do |
| 26 | + let input = opt ^. the @"input" |
| 27 | + let maybeIbOutput = opt ^. the @"ibOutput" |
| 28 | + let maybeBpOutput = opt ^. the @"bpOutput" |
| 29 | + |
| 30 | + cursor <- mmapSlowCursor input |
| 31 | + |
| 32 | + forM_ maybeIbOutput $ flip LBS.writeFile (LBS.toLazyByteString (cursor ^. the @"interests" . the @1)) |
| 33 | + forM_ maybeBpOutput $ flip LBS.writeFile (LBS.toLazyByteString (cursor ^. the @"balancedParens" . the @1)) |
| 34 | + |
| 35 | + return () |
| 36 | + |
| 37 | +optsCreateIndex :: Parser Z.CreateIndexOptions |
| 38 | +optsCreateIndex = Z.CreateIndexOptions |
| 39 | + <$> strOption |
| 40 | + ( long "input" |
| 41 | + <> help "Input file" |
| 42 | + <> metavar "FILE" |
| 43 | + ) |
| 44 | + <*> optional |
| 45 | + ( strOption |
| 46 | + ( long "ib-output" |
| 47 | + <> help "Interest Bits output" |
| 48 | + <> metavar "FILE" |
| 49 | + ) |
| 50 | + ) |
| 51 | + <*> optional |
| 52 | + ( strOption |
| 53 | + ( long "bp-output" |
| 54 | + <> help "Balanced Parens output" |
| 55 | + <> metavar "FILE" |
| 56 | + ) |
| 57 | + ) |
| 58 | + |
| 59 | +cmdCreateIndex :: Mod CommandFields (IO ()) |
| 60 | +cmdCreateIndex = command "create-index" $ flip info idm $ runCreateIndex <$> optsCreateIndex |
0 commit comments