Main.hs (785B)
1 2 module Main where 3 4 import Currency 5 import Data.Scientific 6 import Options.Applicative 7 import Options.Applicative.Types 8 9 main :: IO () 10 main = execParser parserOptions >>= runProgram 11 12 data ExchangeOptions = ExchangeOptions Scientific String String 13 14 -- | Options parser options. 15 parserOptions :: ParserInfo ExchangeOptions 16 parserOptions = info (helper <*> opts) fullDesc where 17 opts = 18 ExchangeOptions 19 <$> argument parseSci (metavar "AMOUNT") 20 <*> argument str (metavar "CURRENCY") 21 <*> argument str (metavar "CURRENCY") 22 23 runProgram :: ExchangeOptions -> IO () 24 runProgram (ExchangeOptions d x y) = do 25 val <- query d x y 26 putStrLn $ show d <> "@" <> x <> "/" <> y <> ": " <> show val 27 28 parseSci :: ReadM Scientific 29 parseSci = do 30 sci <- readerAsk 31 return $ read sci 32