Refactor error message for argument mismatch to be more generic

Previously an insufficient amount of arguments to e.g. the 'type' utility resulted in a "Too many arguments" feedback, which can be somewhat confusing. Now if the argument count does not match, a more generic error message is shown.
This commit is contained in:
Sami Niiranen 2014-05-18 10:53:32 +03:00
parent fcc3b46415
commit 4037f5f8e1

View File

@ -84,7 +84,7 @@ parseArgs spec argv
---------------------------------------------------------------- ----------------------------------------------------------------
data GHCModError = SafeList data GHCModError = SafeList
| TooManyArguments String | ArgumentsMismatch String
| NoSuchCommand String | NoSuchCommand String
| CmdArg [String] | CmdArg [String]
| FileNotExist String deriving (Show, Typeable) | FileNotExist String deriving (Show, Typeable)
@ -108,7 +108,7 @@ main = flip E.catches handlers $ do
remainingArgs = tail cmdArg remainingArgs = tail cmdArg
nArgs n f = if length remainingArgs == n nArgs n f = if length remainingArgs == n
then f then f
else E.throw (TooManyArguments cmdArg0) else E.throw (ArgumentsMismatch cmdArg0)
res <- case cmdArg0 of res <- case cmdArg0 of
"list" -> listModules opt cradle "list" -> listModules opt cradle
"lang" -> listLanguages opt "lang" -> listLanguages opt
@ -135,8 +135,8 @@ main = flip E.catches handlers $ do
handler1 = print -- for debug handler1 = print -- for debug
handler2 :: GHCModError -> IO () handler2 :: GHCModError -> IO ()
handler2 SafeList = printUsage handler2 SafeList = printUsage
handler2 (TooManyArguments cmd) = do handler2 (ArgumentsMismatch cmd) = do
hPutStrLn stderr $ "\"" ++ cmd ++ "\": Too many arguments" hPutStrLn stderr $ "\"" ++ cmd ++ "\": Arguments did not match"
printUsage printUsage
handler2 (NoSuchCommand cmd) = do handler2 (NoSuchCommand cmd) = do
hPutStrLn stderr $ "\"" ++ cmd ++ "\" not supported" hPutStrLn stderr $ "\"" ++ cmd ++ "\" not supported"