Skip to content

Commit 92e5216

Browse files
authored
Merge pull request #75 from haskell-works/new-create-blanked-xml-command
New create-banked-xml command
2 parents eafe16e + f58b31e commit 92e5216

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

app/App/Commands.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module App.Commands where
22

33
import App.Commands.Count
4+
import App.Commands.CreateBlankedXml
45
import App.Commands.CreateBpIndex
56
import App.Commands.CreateIbIndex
67
import App.Commands.CreateIndex
78
import App.Commands.Demo
8-
import Data.Semigroup ((<>))
9+
import Data.Semigroup ((<>))
910
import Options.Applicative
1011

1112
commands :: Parser (IO ())
@@ -16,6 +17,7 @@ commandsGeneral = subparser $ mempty
1617
<> commandGroup "Commands:"
1718
<> cmdCount
1819
<> cmdCreateIndex
20+
<> cmdCreateBlankedXml
1921
<> cmdCreateIbIndex
2022
<> cmdCreateBpIndex
2123
<> cmdDemo
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.CreateBlankedXml
10+
( cmdCreateBlankedXml
11+
) where
12+
13+
import Control.Lens
14+
import Data.Generics.Product.Any
15+
import Data.Semigroup ((<>))
16+
import HaskellWorks.Data.Xml.Internal.ToIbBp64
17+
import HaskellWorks.Data.Xml.Succinct.Cursor.BlankedXml
18+
import Options.Applicative hiding (columns)
19+
20+
import qualified App.Commands.Types as Z
21+
import qualified Data.ByteString.Lazy as LBS
22+
23+
runCreateBlankedXml :: Z.CreateBlankedXmlOptions -> IO ()
24+
runCreateBlankedXml opt = do
25+
let input = opt ^. the @"input"
26+
let output = opt ^. the @"output"
27+
28+
lbs <- LBS.readFile input
29+
let blankedXml = lbsToBlankedXml lbs
30+
LBS.writeFile output (LBS.fromChunks (blankedXml ^. the @1))
31+
32+
return ()
33+
34+
optsCreateBlankedXml :: Parser Z.CreateBlankedXmlOptions
35+
optsCreateBlankedXml = Z.CreateBlankedXmlOptions
36+
<$> strOption
37+
( long "input"
38+
<> help "Input file"
39+
<> metavar "FILE"
40+
)
41+
<*> strOption
42+
( long "output"
43+
<> help "Blanked XML output"
44+
<> metavar "FILE"
45+
)
46+
47+
cmdCreateBlankedXml :: Mod CommandFields (IO ())
48+
cmdCreateBlankedXml = command "create-blanked-xml" $ flip info idm $ runCreateBlankedXml <$> optsCreateBlankedXml

app/App/Commands/Types.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
module App.Commands.Types
55
( CountOptions(..)
6-
, CreateIndexOptions(..)
7-
, CreateIbIndexOptions(..)
6+
, CreateBlankedXmlOptions(..)
87
, CreateBpIndexOptions(..)
8+
, CreateIbIndexOptions(..)
9+
, CreateIndexOptions(..)
910
, DemoOptions(..)
1011
) where
1112

@@ -27,6 +28,11 @@ data CreateIndexOptions = CreateIndexOptions
2728
, bpOutput :: FilePath
2829
} deriving (Eq, Show, Generic)
2930

31+
data CreateBlankedXmlOptions = CreateBlankedXmlOptions
32+
{ input :: FilePath
33+
, output :: FilePath
34+
} deriving (Eq, Show, Generic)
35+
3036
data CreateIbIndexOptions = CreateIbIndexOptions
3137
{ input :: FilePath
3238
, output :: FilePath

hw-xml.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ executable hw-xml
139139
other-modules: Paths_hw_xml
140140
App.Commands
141141
App.Commands.Count
142+
App.Commands.CreateBlankedXml
143+
App.Commands.CreateBpIndex
142144
App.Commands.CreateIbIndex
143145
App.Commands.CreateIndex
144-
App.Commands.CreateBpIndex
145146
App.Commands.Demo
146147
App.Commands.Types
147148
App.Options

src/HaskellWorks/Data/Xml/Succinct/Cursor/BlankedXml.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveGeneric #-}
12

23
module HaskellWorks.Data.Xml.Succinct.Cursor.BlankedXml
34
( BlankedXml(..)
@@ -7,13 +8,16 @@ module HaskellWorks.Data.Xml.Succinct.Cursor.BlankedXml
78
, lbsToBlankedXml
89
) where
910

11+
import GHC.Generics
1012
import HaskellWorks.Data.Xml.Conduit.Blank
1113

1214
import qualified Data.ByteString as BS
1315
import qualified Data.ByteString.Lazy as LBS
1416
import qualified HaskellWorks.Data.ByteString as BS
1517

16-
newtype BlankedXml = BlankedXml [BS.ByteString] deriving (Eq, Show)
18+
newtype BlankedXml = BlankedXml
19+
{ unblankedXml :: [BS.ByteString]
20+
} deriving (Eq, Show, Generic)
1721

1822
getBlankedXml :: BlankedXml -> [BS.ByteString]
1923
getBlankedXml (BlankedXml bs) = bs

0 commit comments

Comments
 (0)