Safe Haskell | Safe-Infered |
---|
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
SampleParser
.
- data OptSpec = OptSpec {}
- data Intersperse
- data Result
- data Args
- noArg :: Args
- optionalArg :: Args
- oneArg :: Args
- twoArg :: Args
- variableArg :: Args
- data SimpleError
- getArgs :: IO [String]
- parse :: Intersperse -> [OptSpec] -> [String] -> Either SimpleError [Result]
Documentation
Specifies each option that your program accepts.
OptSpec | |
|
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 |
Holds the result of command line parsing. Each option (along with its option arguments) or positional argument is assigned to its own Result.
This datatype does dual duty. When part of an OptSpec
, you use
it to specify how many arguments, if any, an option takes. When you
use it for this purpose, it only matters which data constructor you
use; the fields can be any value, even undefined
.
When part of a Result, Args
indicates what arguments the user
supplied to the option.
NoArg | This option takes no arguments |
OptionalArg | This option takes an optional argument. As noted in "The Tao
of Option Parsing", optional arguments can result in some
ambiguity. (Read it here:
http://optik.sourceforge.net/doc/1.5/tao.html) If option |
OneArg | This option takes one argument. Here, if option |
TwoArg | This option takes two arguments. Parsed similarly to |
VariableArg | This option takes a variable number of arguments--zero or
more. Option arguments continue until the command line contains
a word that begins with a hyphen. For example, if option |
Specify that this option takes an optional argument.
Specify that this option takes a variable number of arguments.
data SimpleError Source
A simple type that is already an instance of Error
.
Computation getArgs
returns a list of the program's command
line arguments (not including the program name).
:: Intersperse | |
-> [OptSpec] | |
-> [String] | The command line to parse. This function correctly handles
Unicode strings; however, because |
-> Either SimpleError [Result] |
Parse a command line.