mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-05 12:08:46 +00:00
Compare commits
1 Commits
WoofWare.M
...
WoofWare.M
Author | SHA1 | Date | |
---|---|---|---|
|
49ecfbf5e5 |
@@ -3635,6 +3635,9 @@ module FlagsIntoPositionalArgsArgParse =
|
||||
| Error exc ->
|
||||
if setFlagValue key then
|
||||
go ParseState_FlagsIntoPositionalArgs.AwaitingKey (arg :: args)
|
||||
else if true then
|
||||
key |> arg_1.Add
|
||||
go ParseState_FlagsIntoPositionalArgs.AwaitingKey (arg :: args)
|
||||
else
|
||||
match exc with
|
||||
| None ->
|
||||
@@ -3796,6 +3799,9 @@ module FlagsIntoPositionalArgs'ArgParse =
|
||||
| Error exc ->
|
||||
if setFlagValue key then
|
||||
go ParseState_FlagsIntoPositionalArgs'.AwaitingKey (arg :: args)
|
||||
else if false then
|
||||
key |> arg_1.Add
|
||||
go ParseState_FlagsIntoPositionalArgs'.AwaitingKey (arg :: args)
|
||||
else
|
||||
match exc with
|
||||
| None ->
|
||||
|
@@ -623,30 +623,32 @@ Required argument '--exact' received no value"""
|
||||
let ``Can collect *all* non-help args into positional args with includeFlagLike`` () =
|
||||
let getEnvVar (_ : string) = failwith "do not call"
|
||||
|
||||
FlagsIntoPositionalArgs.parse' getEnvVar [ "--a" ; "foo" ; "--b=false" ; "--c=hi" ; "--" ; "--help" ]
|
||||
FlagsIntoPositionalArgs.parse' getEnvVar [ "--a" ; "foo" ; "--b=false" ; "--c" ; "hi" ; "--" ; "--help" ]
|
||||
|> shouldEqual
|
||||
{
|
||||
A = "foo"
|
||||
GrabEverything = [ "--b=false" ; "--c=hi" ; "--help" ]
|
||||
GrabEverything = [ "--b=false" ; "--c" ; "hi" ; "--help" ]
|
||||
}
|
||||
|
||||
// Users might consider this eccentric!
|
||||
// But we're only a simple arg parser; we don't look around to see whether this is "almost"
|
||||
// a valid parse.
|
||||
FlagsIntoPositionalArgs.parse' getEnvVar [ "--a" ; "--b=false" ; "--c=hi" ; "--" ; "--help" ]
|
||||
FlagsIntoPositionalArgs.parse' getEnvVar [ "--a" ; "--b=false" ; "--c" ; "hi" ; "--" ; "--help" ]
|
||||
|> shouldEqual
|
||||
{
|
||||
A = "--b=false"
|
||||
GrabEverything = [ "--c=hi" ; "--help" ]
|
||||
GrabEverything = [ "--c" ; "hi" ; "--help" ]
|
||||
}
|
||||
|
||||
[<Test>]
|
||||
let ``Can refuse to collect non-help args`` () =
|
||||
let ``Can refuse to collect non-help args with PositionalArgs false`` () =
|
||||
let getEnvVar (_ : string) = failwith "do not call"
|
||||
|
||||
let exc =
|
||||
Assert.Throws<exn> (fun () ->
|
||||
FlagsIntoPositionalArgs'.parse' getEnvVar [ "--a" ; "foo" ; "--b=false" ; "--c=hi" ; "--" ; "--help" ]
|
||||
FlagsIntoPositionalArgs'.parse'
|
||||
getEnvVar
|
||||
[ "--a" ; "foo" ; "--b=false" ; "--c" ; "hi" ; "--" ; "--help" ]
|
||||
|> ignore<FlagsIntoPositionalArgs'>
|
||||
)
|
||||
|
||||
|
@@ -1019,12 +1019,12 @@ module internal ArgParserGenerator =
|
||||
recurseKey
|
||||
]
|
||||
|
||||
let notMatched =
|
||||
let posAttr =
|
||||
match leftoverArgAcc with
|
||||
| ChoicePositional.Choice a
|
||||
| ChoicePositional.Normal a -> a
|
||||
let posAttr =
|
||||
match leftoverArgAcc with
|
||||
| ChoicePositional.Choice a
|
||||
| ChoicePositional.Normal a -> a
|
||||
|
||||
let notMatched =
|
||||
let handleFailure =
|
||||
[
|
||||
SynMatchClause.create (SynPat.named "None") fail
|
||||
@@ -1113,6 +1113,8 @@ module internal ArgParserGenerator =
|
||||
let processValue =
|
||||
// During failure, we've received an optional exception message that happened when we tried to parse
|
||||
// the value; it's in the variable `exc`.
|
||||
// `fail` is for the case where we're genuinely emitting an error.
|
||||
// If we're in `PositionalArgs true` mode, though, we won't call `fail`.
|
||||
let fail =
|
||||
[
|
||||
SynExpr.createIdent "failwithf"
|
||||
@@ -1132,6 +1134,21 @@ module internal ArgParserGenerator =
|
||||
]
|
||||
|> SynExpr.createMatch (SynExpr.createIdent "exc")
|
||||
|
||||
let onFailure =
|
||||
match posAttr with
|
||||
| None -> fail
|
||||
| Some includeFlagLike ->
|
||||
[
|
||||
SynExpr.createIdent "key"
|
||||
|> SynExpr.pipeThroughFunction (SynExpr.createLongIdent' [ leftoverArgs ; Ident.create "Add" ])
|
||||
|
||||
SynExpr.createIdent "go"
|
||||
|> SynExpr.applyTo (SynExpr.createLongIdent' [ parseState ; Ident.create "AwaitingKey" ])
|
||||
|> SynExpr.applyTo (SynExpr.listCons (SynExpr.createIdent "arg") (SynExpr.createIdent "args"))
|
||||
]
|
||||
|> SynExpr.sequential
|
||||
|> SynExpr.ifThenElse includeFlagLike fail
|
||||
|
||||
[
|
||||
SynMatchClause.create
|
||||
(SynPat.nameWithArgs "Ok" [ SynPat.unit ])
|
||||
@@ -1144,7 +1161,7 @@ module internal ArgParserGenerator =
|
||||
(SynPat.nameWithArgs "Error" [ SynPat.named "exc" ])
|
||||
(SynExpr.ifThenElse
|
||||
(SynExpr.applyFunction (SynExpr.createIdent "setFlagValue") (SynExpr.createIdent "key"))
|
||||
fail
|
||||
onFailure
|
||||
(SynExpr.createIdent "go"
|
||||
|> SynExpr.applyTo (SynExpr.createLongIdent' [ parseState ; Ident.create "AwaitingKey" ])
|
||||
|> SynExpr.applyTo (SynExpr.listCons (SynExpr.createIdent "arg") (SynExpr.createIdent "args"))))
|
||||
|
Reference in New Issue
Block a user