This module contains functions pertaining to command line argument handling.

mapToArgs<'T> : 'T → string
Map a type instance to arguments.

mapToClass<'T> : string → Choice<'T,string × string>
Map arguments to a CLI class instance.

mapToRecord<'T> : string → Choice<'T,string × string>
Map arguments to a F# record instance.

usage<'T> : string
Create argument usage text from a type.


Declare a record which the arguments will be mapped to:
type ArgDefs= {
    A : System.Collections.Generic.List<int option>
    B : System.Collections.Generic.Dictionary<byte, string>
    C : int
    D : bool 
    E : int option }

Parse the arguments:
let args = "-A [1] -B {1->\"2\",2->\"10\"} -C 123 -D false" //Argument E is optional and has been omitted.
let value = Arguments.mapToRecord<ArgDefs> args

match value with
| Choice1Of2 (margs) -> 
    Console.WriteLine (sprintf "%A" margs) // Make use of the args record here!!!
| Choice2Of2 (error,usage) -> 
    Console.WriteLine (sprintf "%s\r\n%s" error usage) // Display errors and usage text.

Last edited Mar 19, 2012 at 10:56 AM by huwman, version 5


No comments yet.