Module OptParse

Summary of exported operations:

long :: String -> Mod   
Set the long name of an option.
short :: String -> Mod   
Set the short name of an option.
optional :: Mod   
Set the optional flag of an argument.
metavar :: String -> Mod   
Set the metavar of an argument.
help :: String -> Mod   
Set the help text of an argument.
(<>) :: Mod -> Mod -> Mod   
Combine two modifiers.
option :: (String -> a) -> Mod -> [Parser a]   
Create an option.
arg :: (String -> a) -> Mod -> [Parser a]   
Create a positional argument.
rest :: (String -> a) -> Mod -> [Parser a]   
Create an argument that consumes the rest of the command line.
flag :: a -> Mod -> [Parser a]   
Create a flag.
(<.>) :: [a] -> [a] -> [a]   
Combine two arguments.
(<|>) :: [a] -> [a] -> [a]   
Combine command sub parsers.
command :: String -> Mod -> a -> [Parser a] -> [(String,ArgProps,a,ParseSpec a)]   
Create a sub-parser for a command.
optParser :: [Parser a] -> ParseSpec a   
Create a parse spec from a list of parsers.
commands :: Mod -> [(String,ArgProps,a,ParseSpec a)] -> [Parser a]   
Create a command parser.
printUsage :: String -> Int -> ParseSpec a -> IO ()   
Print usage information for a command line parser specification.
renderUsage :: String -> Int -> ParseSpec a -> String   
Render usage information to a string.
parse :: String -> ParseSpec a -> String -> Either String [a]   
Parses a command line via a parser spec.

Exported datatypes:


Arg

A command line argument. Used to represent a parsed command line.

Constructors:


Parser

A partial command line parser.

Constructors:


ParseSpec

A parser specification. A collection of parsers.

Constructors:


ArgProps

Properties that for all parser types.

Constructors:


OptProps

Properties for option/flag parsers.

Constructors:


Mod

Modifiers for argument and option properties.

Constructors:


Exported operations:

long :: String -> Mod   

Set the long name of an option.

Further infos:
  • solution complete, i.e., able to compute all solutions

short :: String -> Mod   

Set the short name of an option.

Further infos:
  • solution complete, i.e., able to compute all solutions

optional :: Mod   

Set the optional flag of an argument.

Further infos:
  • solution complete, i.e., able to compute all solutions

metavar :: String -> Mod   

Set the metavar of an argument. The metavar is used to print usage information.

Further infos:
  • solution complete, i.e., able to compute all solutions

help :: String -> Mod   

Set the help text of an argument. Used to print usage information.

Further infos:
  • solution complete, i.e., able to compute all solutions

(<>) :: Mod -> Mod -> Mod   

Combine two modifiers.

option :: (String -> a) -> Mod -> [Parser a]   

Create an option.

Example call:
(option f m)
Parameters:
  • f : function that converts the parsed value into a parse result
  • m : modifiers for this argument

arg :: (String -> a) -> Mod -> [Parser a]   

Create a positional argument.

Example call:
(arg f m)
Parameters:
  • f : function that converts the parsed value into a parse result
  • m : modifiers for this argument

rest :: (String -> a) -> Mod -> [Parser a]   

Create an argument that consumes the rest of the command line.

Example call:
(rest f m)
Parameters:
  • f : function that converts the parsed value into a parse result
  • m : modifiers for this argument

flag :: a -> Mod -> [Parser a]   

Create a flag.

Example call:
(flag a m)
Parameters:
  • a : result of the parser
  • m : modifiers for this argument

(<.>) :: [a] -> [a] -> [a]   

Combine two arguments.

Further infos:
  • defined as left-associative infix operator with precedence 4
  • solution complete, i.e., able to compute all solutions

(<|>) :: [a] -> [a] -> [a]   

Combine command sub parsers.

Further infos:
  • defined as left-associative infix operator with precedence 5
  • solution complete, i.e., able to compute all solutions

command :: String -> Mod -> a -> [Parser a] -> [(String,ArgProps,a,ParseSpec a)]   

Create a sub-parser for a command. Must be used with commands.

Example call:
(command n m a ps)
Parameters:
  • n : the name of the command
  • m : modifiers for this command
  • a : the result of this parse
  • ps : parsers for the rest of the command line for this command

optParser :: [Parser a] -> ParseSpec a   

Create a parse spec from a list of parsers.

Further infos:
  • solution complete, i.e., able to compute all solutions

commands :: Mod -> [(String,ArgProps,a,ParseSpec a)] -> [Parser a]   

Create a command parser.

Example call:
(commands m cs)
Parameters:
  • m : modifiers for this command
  • cs : command sub-parsers, created by command

printUsage :: String -> Int -> ParseSpec a -> IO ()   

Print usage information for a command line parser specification.

Example call:
(printUsage p c p)
Parameters:
  • p : the name of the current program
  • c : the maximum number of columns to use
  • p : the parser specification

renderUsage :: String -> Int -> ParseSpec a -> String   

Render usage information to a string.

Example call:
(renderUsage p c p)
Parameters:
  • p : the name of the current program
  • c : the maximum number of columns to use
  • p : the parser specification

parse :: String -> ParseSpec a -> String -> Either String [a]   

Parses a command line via a parser spec.

Example call:
(parse l s p)
Parameters:
  • l : the command line
  • s : the parser spec
  • p : the name of the current program