Created
September 27, 2011 16:42
-
-
Save tsurushuu/1245571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import System.Environment (getArgs) | |
import System.Console.GetOpt | |
data SearchOptions | |
= Query String | Rpp Int | Lang String | OutputFile String | |
deriving (Show) | |
options :: [OptDescr SearchOptions] | |
options = [ | |
Option ['q'] ["query"] (ReqArg Query "QUERY") "query string", | |
Option ['r'] ["rpp"] (ReqArg (Rpp . read) "RPP") "RPP", | |
Option ['l'] ["lang", "language"] (ReqArg Lang "LANG") "language", | |
Option ['o'] [] (ReqArg OutputFile "OUTPUT") "output file" | |
] | |
main :: IO () | |
main = do | |
args <- getArgs | |
case getOpt Permute options args of | |
(o, n, []) -> print (o, n) | |
(_, _, errors) -> ioError (userError (concat errors ++ usageInfo "help" options) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment