F# demo

FSharp · Script

/Program.fs

// @nuget: CommandLineParser.FSharp -Version 2.8.0

open System
open System.Collections
open System.Collections.Generic
open System.Linq
open System.Text
open System.IO
open CommandLine



type options = {
  [<Option('r', "read", Required = true, HelpText = "Input files.")>] files : string;
  [<Option(HelpText = "Prints all messages to standard output.")>] verbose : bool;
  [<Option(Default = "english", HelpText = "Content language.")>] language : string;  
  [<Value(0, MetaName="offset", HelpText = "File offset.")>] offset : int option;
}

let run (o : options)  =
    printfn "Parser success"
    printfn "files= %A verbose= %b language= %s offset= %i" o.files o.verbose o.language o.offset.Value
    

let fail (e : IEnumerable<Error>)  =
    printfn "fail"
  
    
let main argv =
  printfn "Args= %A" argv
  let result = CommandLine.Parser.Default.ParseArguments<options>(argv)
  match result with
  | :? Parsed<options> as parsed -> run parsed.Value
  | :? NotParsed<options> as notParsed -> fail notParsed.Errors
  


printfn "Hello Fsharp with CommandLineParser"
let args = [ "5";"-r"; "f.txt"; "--verbose" ]

main args

;