33 lines
795 B
Haskell
33 lines
795 B
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
module Main where
|
|
|
|
import Options.Applicative
|
|
|
|
import Data.Text
|
|
(Text)
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Control.Addressbook.Query as Query
|
|
import qualified Control.Addressbook.Streaming as Streaming
|
|
|
|
data CmdLine
|
|
= Stream
|
|
| Query Text
|
|
deriving Show
|
|
|
|
cmdline :: Parser CmdLine
|
|
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"))
|
|
)
|
|
|
|
handler :: CmdLine -> IO ()
|
|
handler = \case
|
|
Stream -> Streaming.run
|
|
Query q -> Query.query q
|
|
|
|
main :: IO ()
|
|
main = execParser opts >>= handler
|
|
where
|
|
opts = info (cmdline <**> helper) (fullDesc <> progDesc "Email addressbook")
|