(*** hide ***) // This block of code is omitted in the generated HTML documentation. Use // it to define helpers that you do not want to show in the documentation. #I "../../build" #r "CommandLine.dll" open System (** # Tutorial ## Introduction The library parses command line arguments to a record decorated with attributes: *) type options = { [] root : string; [] indexFiles : seq; [] verbose : bool; [] timeout : int option; [] root : string; [] indexFiles : seq; [] verbose : bool; [] timeout : int option; [(argv) match result with | :? Parsed<'a> as parsed -> runLogic(parsed.Value) | :? NotParsed<'a> as notParsed -> exitApp(notParsed.Errors) | _ -> failwith "invalid parser result" (** The parsed record instance is wrapped in a ParserResult<'a> type. Normally you don't need to match against NotParsed<'a> since errors automatically used by the library to generated the help screen. To disable this feature, just build and configure the Parser instance by your own. ## Syntax Syntax is defined by attribute attached to record fields: *) type options = { [] fileName : string; [] section : string; } (** In this case, * `fileName`: is mandatory since it's marked with `Required=true`. * `ftpUrl`, `ftpPort`: can't be specified along with `httpUrl` and `httpPort`, since set are mutually exclusive. * `section`: it's a value with positional index equal to `0`. Few things to note: * `fptUrl` and `httpUrl` are defined using a non primitive datatype like `System.Uri`; the library automatically supports any type that owns a constructor that accepts a string. * Index of positional arguments defined with `Value` attribute is calculated excluding named options and their values. ## Unparsing Machinery CommandLineParser allows you to create a command line string from a record instance, (obtained from parsing or hand-crafted): *) open System.Diagnostics let arguments : string = Parser.FormatCommandLine { inputFile = "file.xml"; outputFile = "file.bin"; verbose = true } Process.Start("app.exe", arguments)