blob: 96a31930bdb5f855e524978189117ec7b9a92575 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
{-# LANGUAGE OverloadedStrings #-}
module MdBlocks.CLI where
import qualified Data.Aeson.Encode.Pretty as JSON
import qualified Data.ByteString.Lazy.Char8 as BL
import Options.Applicative
import MdBlocks.Repository
data Command
= List FilePath
| Extract String
| ShowMeta String
runCLI :: IO ()
runCLI =
execParser opts >>= run
where
opts = info parser mempty
parser :: Parser Command
parser =
listP
<|> extractP
<|> showP
listP :: Parser Command
listP =
List <$> strOption
(long "file")
extractP :: Parser Command
extractP =
Extract <$> strOption
(long "extract")
showP :: Parser Command
showP =
ShowMeta <$> strOption
(long "show")
run :: Command -> IO ()
run (List fp) = do
bs <- loadBlocks fp
BL.putStrLn $
JSON.encodePretty bs
run (Extract addr) =
putStrLn ("extract not implemented yet: " ++ addr)
run (ShowMeta addr) =
putStrLn ("show not implemented yet: " ++ addr)
|