提交 76b1482f 编写于 作者: V Vidar Holen

Avoid using `error` for option parsing failure

上级 49250ead
...@@ -221,20 +221,28 @@ runFormatter sys format options files = do ...@@ -221,20 +221,28 @@ runFormatter sys format options files = do
then NoProblems then NoProblems
else SomeProblems else SomeProblems
parseColorOption colorOption = parseEnum name value list =
case colorOption of case filter ((== value) . fst) list of
"auto" -> ColorAuto [(name, value)] -> return value
"always" -> ColorAlways [] -> do
"never" -> ColorNever printErr $ "Unknown value for --" ++ name ++ ". " ++
_ -> error $ "Bad value for --color `" ++ colorOption ++ "'" "Valid options are: " ++ (intercalate ", " $ map fst list)
throwError SupportFailure
parseSeverityOption severityOption =
case severityOption of parseColorOption value =
"error" -> ErrorC parseEnum "color" value [
"warning" -> WarningC ("auto", ColorAuto),
"info" -> InfoC ("always", ColorAlways),
"style" -> StyleC ("never", ColorNever)
_ -> error $ "Bad value for --severity `" ++ severityOption ++ "'" ]
parseSeverityOption value =
parseEnum "severity" value [
("error", ErrorC),
("warning", WarningC),
("info", InfoC),
("style", StyleC)
]
parseOption flag options = parseOption flag options =
case flag of case flag of
...@@ -265,10 +273,11 @@ parseOption flag options = ...@@ -265,10 +273,11 @@ parseOption flag options =
externalSources = True externalSources = True
} }
Flag "color" color -> Flag "color" color -> do
option <- parseColorOption color
return options { return options {
formatterOptions = (formatterOptions options) { formatterOptions = (formatterOptions options) {
foColorOption = parseColorOption color foColorOption = option
} }
} }
...@@ -279,10 +288,11 @@ parseOption flag options = ...@@ -279,10 +288,11 @@ parseOption flag options =
} }
} }
Flag "severity" severity -> Flag "severity" severity -> do
option <- parseSeverityOption severity
return options { return options {
checkSpec = (checkSpec options) { checkSpec = (checkSpec options) {
csMinSeverity = parseSeverityOption severity csMinSeverity = option
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册