Skip to content

Commit f028c6b

Browse files
authored
Merge pull request #71 from haskell-works/new-create-index-command
New create-index command
2 parents 2db271a + 924fa34 commit f028c6b

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

app/App/Commands/CreateIndex.hs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

app/App/Commands/Types.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
module App.Commands.Types
55
( CountOptions(..)
6+
, CreateIndexOptions(..)
67
, DemoOptions(..)
78
) where
89

@@ -17,3 +18,9 @@ data CountOptions = CountOptions
1718
, xpath :: XPath
1819
, method :: Text
1920
} deriving (Eq, Show, Generic)
21+
22+
data CreateIndexOptions = CreateIndexOptions
23+
{ input :: FilePath
24+
, ibOutput :: Maybe FilePath
25+
, bpOutput :: Maybe FilePath
26+
} deriving (Eq, Show, Generic)

hw-xml.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ common generic-lens { build-depends: generic-lens >=
3737
common ghc-prim { build-depends: ghc-prim >= 0.5 && < 0.6 }
3838
common hedgehog { build-depends: hedgehog >= 1.0 && < 1.1 }
3939
common hspec { build-depends: hspec >= 2.5 && < 3.0 }
40-
common hw-balancedparens { build-depends: hw-balancedparens >= 0.3.0.0 && < 0.4 }
41-
common hw-bits { build-depends: hw-bits >= 0.7.0.6 && < 0.8 }
40+
common hw-balancedparens { build-depends: hw-balancedparens >= 0.3.0.1 && < 0.4 }
41+
common hw-bits { build-depends: hw-bits >= 0.7.0.7 && < 0.8 }
4242
common hw-hspec-hedgehog { build-depends: hw-hspec-hedgehog >= 0.1 && < 0.2 }
4343
common hw-parser { build-depends: hw-parser >= 0.1.0.1 && < 0.2 }
4444
common hw-prim { build-depends: hw-prim >= 0.6.2.33 && < 0.7 }
@@ -139,6 +139,7 @@ executable hw-xml
139139
other-modules: Paths_hw_xml
140140
App.Commands
141141
App.Commands.Count
142+
App.Commands.CreateIndex
142143
App.Commands.Demo
143144
App.Commands.Types
144145
App.Options

0 commit comments

Comments
 (0)