Querying
This commit is contained in:
		
							
								
								
									
										12
									
								
								app/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								app/Main.hs
									
									
									
									
									
								
							@@ -3,18 +3,28 @@ 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")))
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user