Add command-line option -S/--severity

Specifies the maximum severity of errors to handle.  For example,
specifying "-S warning" means that errors of severity "info" and
"style" are ignored.

Signed-off-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Martin Schwenke
2018-08-12 21:28:48 +10:00
committed by Vidar Holen
parent 15aaacf715
commit b16da4b242
4 changed files with 33 additions and 5 deletions

View File

@@ -67,7 +67,8 @@ instance Monoid Status where
data Options = Options {
checkSpec :: CheckSpec,
externalSources :: Bool,
formatterOptions :: FormatterOptions
formatterOptions :: FormatterOptions,
maxSeverity :: Severity
}
defaultOptions = Options {
@@ -75,7 +76,8 @@ defaultOptions = Options {
externalSources = False,
formatterOptions = FormatterOptions {
foColorOption = ColorAuto
}
},
maxSeverity = StyleC
}
usageHeader = "Usage: shellcheck [OPTIONS...] FILES..."
@@ -93,6 +95,9 @@ options = [
Option "s" ["shell"]
(ReqArg (Flag "shell") "SHELLNAME")
"Specify dialect (sh, bash, dash, ksh)",
Option "S" ["severity"]
(ReqArg (Flag "severity") "SEVERITY")
"Maximum severity of errors to consider (error, warning, info, style)",
Option "V" ["version"]
(NoArg $ Flag "version" "true") "Print version information",
Option "x" ["external-sources"]
@@ -223,6 +228,14 @@ parseColorOption colorOption =
"never" -> ColorNever
_ -> error $ "Bad value for --color `" ++ colorOption ++ "'"
parseSeverityOption severityOption =
case severityOption of
"error" -> ErrorC
"warning" -> WarningC
"info" -> InfoC
"style" -> StyleC
_ -> error $ "Bad value for --severity `" ++ severityOption ++ "'"
parseOption flag options =
case flag of
Flag "shell" str ->
@@ -266,6 +279,13 @@ parseOption flag options =
}
}
Flag "severity" severity ->
return options {
checkSpec = (checkSpec options) {
csMaxSeverity = parseSeverityOption severity
}
}
_ -> return options
where
die s = do