Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion demo/fsharp-demo.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -34,3 +36,4 @@ let result = Parser.Default.ParseArguments<options>(args)
match result with
| Success(opts) -> printf "%s" (formatInput opts)
| Fail(errs) -> printf "Invalid: %A, Errors: %u\n" args (Seq.length errs)
| Help | Version -> ()