Merge pull request #261 from saminiir/master

Refactor error message for argument mismatch to be more generic
This commit is contained in:
Kazu Yamamoto 2014-05-19 10:00:13 +09:00
commit 3b3dcbc6e5

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"