getargs as a pure function, instead of an IO action. This
allows to make evaluated command line arguments global values. This
calls
getargs to parse the command line arguments.
GHC.IO.unsafePerformIO is used to take the result out of the
IO monad.
unsafe_getargs header descs = GHC.IO.unsafePerformIO $ getargs "" descs
The
getargs action is performed on demand, when the parse
result is evaluated. It may result in an
ArgError being thrown.
In order to avoid this happening at unexpected times, the
main function should, start with the line
seq args
(return ()), where
args is the result of
unsafe_getargs,. This will trigger any command line argument
errors at the beginning of the program. (See section 6.2 of the Hakell
Report for the definition of
seq).
The header is used only by the deprecated
usage_info
function. If you don't use it, you don't need to specify a header.
Just pass an empty string.
A typical use of
unsafe_getargs looks like this:
descs = [ d_myflag, ... ]
d_myflag = argdesc [ ... ]
args = unsafe_getargs "" descs
myflag = arg_switch args d_myflag
main = mainwrapper $ do
seq args (return ())
...
See
getargs,
unsafe_getargs_ordered.