summaryrefslogtreecommitdiffstats
path: root/src/MdBlocks/CLI.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-09-30 03:21:31 +0200
committertv <tv@krebsco.de>2026-09-30 03:21:31 +0200
commitd5633e2395368410e1dfa22e5a046e655671a981 (patch)
tree790ab6035b4c77829c3070b6d04555181226c0a1 /src/MdBlocks/CLI.hs
init
Diffstat (limited to 'src/MdBlocks/CLI.hs')
-rw-r--r--src/MdBlocks/CLI.hs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/MdBlocks/CLI.hs b/src/MdBlocks/CLI.hs
new file mode 100644
index 0000000..96a3193
--- /dev/null
+++ b/src/MdBlocks/CLI.hs
@@ -0,0 +1,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)