hsoptions- Haskell library that supports command-line flag processing

MaintainerJose Raymundo Cruz (jose.r.cruz01@gmail.com)
Safe HaskellSafe-Inferred



Core functions of the Parser.



operationsKeyMap :: [(String, OperationToken)]Source

Map of operation keywords to the corresponding operation token.

operationKeywords :: [String]Source

Returns a list of all operation keywords.

operationTokenFor :: String -> OperationTokenSource

Returns the corresponding operation token for the input keyword.

flag :: DefaultOp -> GenParser Char st TokenSource

Parses a flag.

A flag consist of a name, followed by an flagOperation and a value.


flagName :: GenParser Char st StringSource

Parses the name of a flag.

The name must follow the pattern of: "flagPrefix letter validFlagChars".


  • A string with the flag name (without the prefix part).

flagPrefix :: GenParser Char st ()Source

Parses the flag prefix.

A flag prefix is a double dash (--) or a single dash (-).

flagOperation :: String -> DefaultOp -> GenParser Char st OperationTokenSource

Parses a flag operation.

Flag operations will be parsed from the keywords defined in the operationsKeyMap.

spaceOrEof :: GenParser Char st ()Source

Parses a space or the end of file character.

notFlag :: GenParser Char st StringSource

Parses a word that is not a flag.

"Not a flag" parses anything that is not parsed by flag parser.

quotedString :: Char -> GenParser Char st StringSource

Parses a quoted string using the character for quotes.


  • character: the character used as quotes.

flagValue :: GenParser Char st FlagValueTokenSource

Parses a flag value.

A flag value is parsed with notFlag. If this parser fails then FlagValueTokenEmpty is returned.

allButSpace :: GenParser Char st StringSource

Parses all characters until a space is found.

cmdLineArg :: GenParser Char st TokenSource

Parses a command line argument.

A command argument is an argument that is not a flag (notFlag).

operation :: GenParser Char st OperationTokenSource

Parses a flag operation.

Returns: a token representing for that operation.

validFlagChars :: GenParser Char st StringSource

Parses and returns the characters that are valid for a flag.

manyToken :: DefaultOp -> GenParser Char st [Token]Source

Parses many flags and/or many positional arguments.


  • A list of tokens.

parseInput' :: DefaultOp -> String -> Either ParseError [Token]Source

Runs parser with the manyToken parser.

parseInput :: DefaultOp -> String -> [Token]Source

Parses the flags from the input stream of characters to a stream of tokens.

Based on the syntax of the flags input this parser should not fail. If there is any kind of errors while parsing an exception is thrown.


  • default_operations: a map from flag name to default operation.
  • input: the input stream of characters.


  • A stream of tokens.


  • An exception if some error with the parser occurs.