on master help sign in
give error messages on non-1 number of ArgErrors with terminal

Fix https://github.com/elm/compiler/issues/1941

commita1c3e30f6157b08c8d18eb51c51e54f91cb47e83 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 3 Jul 2019, 11:43 (7 years ago) parente500d53
1 file changed+16−5
terminal/src/Terminal/Args/Error.hs+16−5
terminal/src/Terminal/Args/Error.hs+16−5
@@ -272,13 +272,24 @@ exitWithError err =
272272 BadArgs argErrors ->
273273 case argErrors of
274274 [] ->
275− error "TODO no possible args"
275+ return
276+ [ reflow $ "I was not expecting any arguments for this command."
277+ , reflow $ "Try removing them?"
278+ ]
276279
277280 [(_args, argError)] ->
278281 argErrorToDocs argError
279282
280283 _:_:_ ->
281− error "TODO show possible arg configurations"
284+ argErrorToDocs $ head $ List.sortOn toArgErrorRank (map snd argErrors)
285+
286+
287+toArgErrorRank :: ArgError -> Int -- lower is better
288+toArgErrorRank err =
289+ case err of
290+ ArgBad _ _ -> 0
291+ ArgMissing _ -> 1
292+ ArgExtras _ -> 2
282293
283294
284295toGreen :: String -> P.Doc
@@ -318,10 +329,10 @@ argErrorToDocs argError =
318329 return
319330 [ "I am having trouble with this argument:"
320331 , P.indent 4 $ toRed string
321− , P.fillSep
332+ , P.fillSep $
322333 ["It","is","supposed","to","be","a"
323− ,toYellow (toToken tipe),"value,","like","this:"
324− ]
334+ ,toYellow (toToken tipe),"value,","like"
335+ ] ++ if length examples == 1 then ["this:"] else ["one","of","these:"]
325336 , P.indent 4 $ P.green $ P.vcat $ map P.text examples
326337 ]
327338