Safe Haskell | Safe-Inferred |
---|
A simple command line parser that can parse options that take an optional argument, one or two arguments, or a variable number of arguments. For sample code that uses this parser, see System.Console.MultiArg.SampleParser.
- data Intersperse
- simple :: Intersperse -> [OptSpec a] -> (String -> a) -> [String] -> Exceptional Error [a]
- data Mode result = forall b . Mode {
- mName :: String
- mIntersperse :: Intersperse
- mOpts :: [OptSpec b]
- mPosArgs :: String -> b
- mProcess :: [b] -> result
- modes :: [OptSpec a] -> ([a] -> Exceptional String b) -> (b -> Either (String -> c) [Mode result]) -> [String] -> Exceptional Error (b, Either [c] result)
Interspersion control
data Intersperse Source
What to do after encountering the first non-option, non-option-argument word on the command line? In either case, no more options are parsed after a stopper.
Intersperse | Additional options are allowed on the command line after
encountering the first positional argument. For example, if |
StopOptions | No additional options will be parsed after encountering the
first positional argument. For example, if |
The parser
:: Intersperse | What to do after encountering the first positional argument |
-> [OptSpec a] | All possible options |
-> (String -> a) | How to handle positional arguments. This function is applied to the appropriate string every time the parser encounters a positional argument. |
-> [String] | The command line to parse. This function correctly handles
Unicode strings; however, because |
-> Exceptional Error [a] |
Parse a command line.
Parsing multi-mode command lines
Provides information on each mode that you wish to parse.
forall b . Mode | |
|
:: [OptSpec a] | Global options. These come after the program name but before the mode name. |
-> ([a] -> Exceptional String b) | This function is applied to all the global options after
they are parsed. To indicate a failure, return an Exception
String; otherwise, return a successful value. This allows you
to process the global options before the mode is parsed. (If
you don't need to do any preprocessing, pass |
-> (b -> Either (String -> c) [Mode result]) | This function determines whether modes will be parsed and,
if so, which ones. The function is applied to the result of
the pre-processing of the global options, so which modes are
parsed and the behavior of those modes can vary depending on
the global options. Return a Left to indicate that you do not
want to parse modes at all. For instance, if the user passed a
|
-> [String] | The command line to parse (presumably from |
-> Exceptional Error (b, Either [c] result) | Returns an Exception if an error was encountered when parsing the command line (including if the global options procesor returned an Exception.) Otherwise, returns a pair. The first element of the pair is the result of the global options processor. The second element of the pair is an Either. It is Left if no modes were parsed, with a list of the positional arguments. It is a Right if modes were parsed, with the result of parsing the arguments to the mode. |
Parses a command line that may feature options followed by a mode followed by more options and then followed by positional arguments.