Skip to content

Instantly share code, notes, and snippets.

@tsurushuu
Created September 27, 2011 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsurushuu/1245571 to your computer and use it in GitHub Desktop.
Save tsurushuu/1245571 to your computer and use it in GitHub Desktop.
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