GetOpt
Enums
enum ArgDescr [a : Type]
SourceArgDescr defines whether or not the option takes an argument.
NoArgexpects no argument. The constructor takes a value of typeaindicating the option that has been recognized.ReqArgmandates an argument. The constructor takes a function to decode the argument and description string.OptArgoptionally requires an argument. The constructor takes a function to decode the argument and description string.
The "decode" functions are expected to produce Some(_) when decoding is successful, and None to indicate
failure.
enum ArgOrder [a : Type]
SourceArgOrder defines how to parse further arguments that follow non-options.
RequireOrderafter the first non-option all remain arguments are treated as non-optionsPermuteoptions and non-options are freely interspersed in the input streamReturnInOrderturn non-options into options by applying the supplied function
Type Aliases
type alias OptionDescr [ a : Type ] = { argDescriptor = ArgDescr[a], explanation = String, optionIds = List[Char], optionNames = List[String] }
SourceAn OptionDescr describes a single command line option.
optionIdsis a list of single character abbreviations identifying the optionoptionNamesis a list of long names identifying the optionargDescriptordefines the format of the optionexplanationis the description of the option printed to the user by the functionusageInfo
Definitions
def
getOpt
[a]
(
ordering :
ArgOrder[a]
optDescriptors :
List[OptionDescr[a]]
sourceArgs :
List[String]
)
: Validation[String, { nonOptions = List[String], options = List[a] }]
\ Pure
Decode the list of command line options supplied to the program.
ordering mandates how processing of options and non-options is handled.
optDescriptors is a list of processors for decoding individual options.
sourceArgs should be the list of command line arguments supplied to the program.
If successful, getOpt returns lists of decoded options and non-options. If unsuccessful it
returns a non-empty list of error messages, with unknown options considered to be errors.
def
getOpt1
[a]
(
ordering :
ArgOrder[a]
optDescriptors :
List[OptionDescr[a]]
sourceArgs :
List[String]
)
: { errors = List[String], nonOptions = List[String], options = List[a], unknowns = List[String] }
\ Pure
This is a more general version of getOpt that returns all the results of decoding the command line
options without distinguishing whether the decoding is successful or a failure.
Client code calling this function, rather than getOpt, is free to process or ignore the results collected
in unknowns and errors which would indicate problems with the decoding if either were not empty.
def
preprocess
(
options :
{ quoteClose = String, quoteOpen = String, stripQuoteMarks = Bool }
args :
List[String]
)
: List[String]
\ Pure
Preprocess the command line arguments before parsing them.
Arguments supplied as an List[String] to the program are simply derived from the input split on space.
This does not account for, for example, Windows file names which may include space.
preprocess is a simple function that can be used to "rejoin" command line arguments if they were
joined by "quotation marks" in the user supplied string (quotations marks are configurable and do not
have to be double quotes).
def
usageInfo
[a]
(
header :
String
optionDescriptors :
List[OptionDescr[a]]
)
: String
\ Pure
Return a formatted string describing the usage of the command.
Typically this output is used by "--help"