{-# 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)