Safe Haskell | None |
---|---|
Language | Haskell2010 |
Exported modules
module Language.Parser
Preprocessing command-line arguments
Describes whether an option takes an argument or not, and if so
how the argument is injected into a value of type a
.
usageInfo :: String -> [OptDescr a] -> String #
Return a string describing the usage of a command, derived from the header (first argument) and the options described by the second argument.
tokenize :: Monad m => [OptDescr a] -> (String -> a) -> ParserT [String] m [a] Source #
Create a Parser that preprocesses the command-line arguments, splitting options and their arguments into a user-defined data type.
Example usage
This module is intended to provide simple parsing functionality to the handling of command-line arguments. Here is an example of how this module may be used.
data Option = Help | Version | Other String deriving Eq options = [ Option ['h'] ["help"] (NoArg Help) "Display this menu.", Option ['v'] ["version"] (NoArg Version) "Show the version of this program" ] mainAxiom = single Help >> lift (putStrLn (usageInfo options)) <+> single Version >> lift (putStrLn "Version: 1.0") main = void $ do getArgs >>= (mainAxiom <*< tokenize options Other)