I’m having a bit problem with reading argument value in haskell:
I’m having options declared like this:
options :: [OptDescr ArgFlag]
options = [Option [] ["help"] (NoArg Help) "",
Option [] ["version"] (NoArg Version) "",
Option ['a'] [] (NoArg FSAll) "",
Option ['L'] [] (ReqArg FSLevel "NUM") ""]
And I read the arguments like this (I can read which argument is active):
main = do
args <- getArgs
case getOpt RequireOrder options args of
([Version], [], []) -> do ...
([Help], [], []) -> do ...
(flags, files, []) -> do ........ *
otherwise -> do ...
Where there is ‘*’ character, I need to read value of possible ‘-l 3’ flag -> I searched through google but I haven’t found nothing (maybe wrong keyword though). They just detect whether argument is active everywhere, not its value.
I presume you have defined
With a helper function
you can then get the value like this:
(You will need to import
mapMaybeandlistToMaybefrom Data.Maybe.)