enum ArgDescr[a: Type]Source
case NoArg(a)case ReqArg(String -> Option[a], String)case OptArg(Option[String] -> Option[a], String)

ArgDescr defines whether or not the option takes an argument.

  • NoArg expects no argument. The constructor takes a value of type a indicating the option that has been recognized.
  • ReqArg mandates an argument. The constructor takes a function to decode the argument and description string.
  • OptArg optionally 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]Source
case RequireOrder(Unit)case Permute(Unit)case ReturnInOrder(String -> a)

ArgOrder defines how to parse further arguments that follow non-options.

  • RequireOrder after the first non-option all remain arguments are treated as non-options
  • Permute options and non-options are freely interspersed in the input stream
  • ReturnInOrder turn 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] }Source

An OptionDescr describes a single command line option.

  • optionIds is a list of single character abbreviations identifying the option
  • optionNames is a list of long names identifying the option
  • argDescriptor defines the format of the option
  • explanation is the description of the option printed to the user by the function usageInfo


def getOpt(ordering: ArgOrder[a], optDescriptors: List[OptionDescr[a]], sourceArgs: List[String]): Validation[String, { nonOptions = List[String], options = List[a] }]Source

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(ordering: ArgOrder[a], optDescriptors: List[OptionDescr[a]], sourceArgs: List[String]): { errors = List[String], nonOptions = List[String], options = List[a], unknowns = List[String] }Source

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]Source

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(header: String, optionDescriptors: List[OptionDescr[a]]): StringSource

Return a formatted string describing the usage of the command.

Typically this output is used by "--help"