addressbook/app/Main.hs

33 lines
795 B
Haskell
Raw Normal View History

2020-12-10 23:08:03 +02:00
{-# LANGUAGE LambdaCase #-}
2020-12-10 19:47:11 +02:00
module Main where
2020-12-10 23:08:03 +02:00
import Options.Applicative
2020-12-11 17:55:52 +02:00
import Data.Text
(Text)
import qualified Data.Text as T
import qualified Control.Addressbook.Query as Query
2020-12-10 23:08:03 +02:00
import qualified Control.Addressbook.Streaming as Streaming
data CmdLine
= Stream
2020-12-11 17:55:52 +02:00
| Query Text
2020-12-10 23:08:03 +02:00
deriving Show
cmdline :: Parser CmdLine
2020-12-11 17:55:52 +02:00
cmdline = subparser
( command "stream" (info (pure Stream) (progDesc "Record a stream of filenames"))
<> command "query" (info (Query . T.pack <$> argument str (metavar "QUERY")) (progDesc "Query email addresses"))
)
2020-12-10 23:08:03 +02:00
handler :: CmdLine -> IO ()
handler = \case
Stream -> Streaming.run
2020-12-11 17:55:52 +02:00
Query q -> Query.query q
2020-12-10 19:47:11 +02:00
main :: IO ()
2020-12-10 23:08:03 +02:00
main = execParser opts >>= handler
where
opts = info (cmdline <**> helper) (fullDesc <> progDesc "Email addressbook")