on master help sign in
give error messages on non-1 number of ArgErrors with terminal
a1c3e30Evan Czaplicki
terminal/src/Terminal/Args/Error.hs+16−5
@@ -272,13 +272,24 @@ exitWithError err =
272 BadArgs argErrors ->
272 BadArgs argErrors ->
273 case argErrors of
273 case argErrors of
274 [] ->
274 [] ->
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+ ]
276
279
277 [(_args, argError)] ->
280 [(_args, argError)] ->
278 argErrorToDocs argError
281 argErrorToDocs argError
279
282
280 _:_:_ ->
283 _:_:_ ->
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
282
293
283
294
284toGreen :: String -> P.Doc
295toGreen :: String -> P.Doc
@@ -318,10 +329,10 @@ argErrorToDocs argError =
318 return
329 return
319 [ "I am having trouble with this argument:"
330 [ "I am having trouble with this argument:"
320 , P.indent 4 $ toRed string
331 , P.indent 4 $ toRed string
321− , P.fillSep
332+ , P.fillSep $
322 ["It","is","supposed","to","be","a"
333 ["It","is","supposed","to","be","a"
323− ,toYellow (toToken tipe),"value,","like","this:"
334+ ,toYellow (toToken tipe),"value,","like"
324− ]
335+ ] ++ if length examples == 1 then ["this:"] else ["one","of","these:"]
325 , P.indent 4 $ P.green $ P.vcat $ map P.text examples
336 , P.indent 4 $ P.green $ P.vcat $ map P.text examples
326 ]
337 ]
327
338