From dfb3098ad9cf9ec04233750f4bae8adce637082e Mon Sep 17 00:00:00 2001 From: Wallace Kelly Date: Tue, 6 Aug 2019 08:49:31 -0400 Subject: [PATCH] In F# demo include Help and Version matching --- demo/fsharp-demo.fsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/demo/fsharp-demo.fsx b/demo/fsharp-demo.fsx index 81b1640d..8aff84e3 100644 --- a/demo/fsharp-demo.fsx +++ b/demo/fsharp-demo.fsx @@ -22,9 +22,11 @@ let formatLong o = let formatInput (o : options) = sprintf "--stringvalue: %s\n-i: %A\n-x: %b\nvalue: %s\n" o.stringValue o.intSequence o.boolValue (formatLong o.longValue) -let inline (|Success|Fail|) (result : ParserResult<'a>) = +let inline (|Success|Help|Version|Fail|) (result : ParserResult<'a>) = match result with | :? Parsed<'a> as parsed -> Success(parsed.Value) + | :? NotParsed<'a> as notParsed when notParsed.Errors.IsHelp() -> Help + | :? NotParsed<'a> as notParsed when notParsed.Errors.IsVersion() -> Version | :? NotParsed<'a> as notParsed -> Fail(notParsed.Errors) | _ -> failwith "invalid parser result" @@ -34,3 +36,4 @@ let result = Parser.Default.ParseArguments(args) match result with | Success(opts) -> printf "%s" (formatInput opts) | Fail(errs) -> printf "Invalid: %A, Errors: %u\n" args (Seq.length errs) + | Help | Version -> ()