File tree Expand file tree Collapse file tree 2 files changed +37
-10
lines changed Expand file tree Collapse file tree 2 files changed +37
-10
lines changed Original file line number Diff line number Diff line change @@ -485,7 +485,7 @@ noArgs =
485485 { description = ""
486486 , parseFn = \args ->
487487 if Array.length args /= 0 then
488- Err <| ArgumentParserWrongArity { expected = 0, actual = ( Array.length args) }
488+ Err <| ArgumentParserWrongArity { expected = 0, actual = Array.length args }
489489
490490 else
491491 Ok {}
@@ -644,7 +644,27 @@ oneOfArgs argParsers =
644644 Ok result
645645
646646 Nothing ->
647- Array.first parseResults
647+ parseResults
648+ |> Array.findFirst
649+ (\result ->
650+ when result is
651+ Ok _ ->
652+ False
653+
654+ Err (ArgumentParserWrongArity _) ->
655+ False
656+
657+ _ ->
658+ True
659+ )
660+ |> (\maybeErr ->
661+ when maybeErr is
662+ Nothing ->
663+ Array.first parseResults
664+
665+ Just err ->
666+ Just err.value
667+ )
648668 |> Maybe.withDefault
649669 (Err <| ArgumentParserInvalidArgument
650670 { argument = String.join " " args
Original file line number Diff line number Diff line change @@ -272,18 +272,18 @@ tests =
272272 testCmdOneOfArgs =
273273 cmdBuilder
274274 (Parser.oneOfArgs
275- [ Parser.twoArgs
276- (\path file ->
277- { path = path, file = file }
278- )
279- Parser.pathParser
280- Parser.grenFileParser
281- , Parser.noArgs
275+ [ Parser.noArgs
282276 |> Parser.mapArgs (\{} ->
283277 { path = Path.fromPosixString ""
284278 , file = Path.fromPosixString ""
285279 }
286280 )
281+ , Parser.twoArgs
282+ (\path file ->
283+ { path = path, file = file }
284+ )
285+ Parser.pathParser
286+ Parser.grenFileParser
287287 ]
288288 )
289289 testFlags
@@ -314,10 +314,17 @@ tests =
314314 runCommand testCmdOneOfArgs [ "make", "src/Dest" ]
315315 |> Expect.equal
316316 (Parser.BadArguments <| Parser.ArgumentParserWrongArity
317- { expected = 2
317+ { expected = 0
318318 , actual = 1
319319 }
320320 )
321+ , test "Tries to find error of matching arity" <| \{} ->
322+ when runCommand testCmdOneOfArgs [ "make", "out.txt", "src/Dest" ] is
323+ Parser.BadArguments (Parser.ArgumentParserInvalidArgument _) ->
324+ Expect.pass
325+
326+ _ ->
327+ Expect.fail "Expected parsing to fail with an invalid argument error"
321328 ]
322329 ]
323330 , describe "Flags"
You can’t perform that action at this time.
0 commit comments