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 =
485
485
{ description = ""
486
486
, parseFn = \args ->
487
487
if Array.length args /= 0 then
488
- Err <| ArgumentParserWrongArity { expected = 0, actual = ( Array.length args) }
488
+ Err <| ArgumentParserWrongArity { expected = 0, actual = Array.length args }
489
489
490
490
else
491
491
Ok {}
@@ -644,7 +644,27 @@ oneOfArgs argParsers =
644
644
Ok result
645
645
646
646
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
+ )
648
668
|> Maybe.withDefault
649
669
(Err <| ArgumentParserInvalidArgument
650
670
{ argument = String.join " " args
Original file line number Diff line number Diff line change @@ -272,18 +272,18 @@ tests =
272
272
testCmdOneOfArgs =
273
273
cmdBuilder
274
274
(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
282
276
|> Parser.mapArgs (\{} ->
283
277
{ path = Path.fromPosixString ""
284
278
, file = Path.fromPosixString ""
285
279
}
286
280
)
281
+ , Parser.twoArgs
282
+ (\path file ->
283
+ { path = path, file = file }
284
+ )
285
+ Parser.pathParser
286
+ Parser.grenFileParser
287
287
]
288
288
)
289
289
testFlags
@@ -314,10 +314,17 @@ tests =
314
314
runCommand testCmdOneOfArgs [ "make", "src/Dest" ]
315
315
|> Expect.equal
316
316
(Parser.BadArguments <| Parser.ArgumentParserWrongArity
317
- { expected = 2
317
+ { expected = 0
318
318
, actual = 1
319
319
}
320
320
)
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"
321
328
]
322
329
]
323
330
, describe "Flags"
You can’t perform that action at this time.
0 commit comments