Fix remaining FIXME for tty error color output.
This commit is contained in:
parent
8acd5b13cd
commit
b4390414ef
|
@ -48,7 +48,6 @@ checkScript sys spec = do
|
|||
results <- checkScript (csScript spec)
|
||||
return CheckResult {
|
||||
crFilename = csFilename spec,
|
||||
crColorOption = csColorOption spec,
|
||||
crComments = results
|
||||
}
|
||||
where
|
||||
|
|
|
@ -27,12 +27,12 @@ import GHC.Exts
|
|||
import System.Info
|
||||
import System.IO
|
||||
|
||||
format :: IO Formatter
|
||||
format = return Formatter {
|
||||
format :: FormatterOptions -> IO Formatter
|
||||
format options = return Formatter {
|
||||
header = return (),
|
||||
footer = return (),
|
||||
onFailure = outputError,
|
||||
onResult = outputResult
|
||||
onFailure = outputError options,
|
||||
onResult = outputResult options
|
||||
}
|
||||
|
||||
colorForLevel level =
|
||||
|
@ -45,12 +45,12 @@ colorForLevel level =
|
|||
"source" -> 0 -- none
|
||||
otherwise -> 0 -- none
|
||||
|
||||
outputError file error = do
|
||||
color <- getColorFunc $ ColorAuto -- FIXME: should respect --color
|
||||
hPutStrLn stderr $ color "error ZZZ" $ file ++ ": " ++ error
|
||||
outputError options file error = do
|
||||
color <- getColorFunc $ foColorOption options
|
||||
hPutStrLn stderr $ color "error" $ file ++ ": " ++ error
|
||||
|
||||
outputResult result contents = do
|
||||
color <- getColorFunc $ crColorOption result
|
||||
outputResult options result contents = do
|
||||
color <- getColorFunc $ foColorOption options
|
||||
let comments = crComments result
|
||||
let fileLines = lines contents
|
||||
let lineCount = fromIntegral $ length fileLines
|
||||
|
|
|
@ -34,30 +34,21 @@ data CheckSpec = CheckSpec {
|
|||
csFilename :: String,
|
||||
csScript :: String,
|
||||
csExcludedWarnings :: [Integer],
|
||||
csColorOption :: ColorOptions,
|
||||
csShellTypeOverride :: Maybe Shell
|
||||
} deriving (Show, Eq)
|
||||
|
||||
data CheckResult = CheckResult {
|
||||
crFilename :: String,
|
||||
crComments :: [PositionedComment],
|
||||
crColorOption :: ColorOptions
|
||||
crComments :: [PositionedComment]
|
||||
} deriving (Show, Eq)
|
||||
|
||||
emptyCheckSpec = CheckSpec {
|
||||
csFilename = "",
|
||||
csScript = "",
|
||||
csExcludedWarnings = [],
|
||||
csShellTypeOverride = Nothing,
|
||||
csColorOption = ColorAuto
|
||||
csShellTypeOverride = Nothing
|
||||
}
|
||||
|
||||
data ColorOptions =
|
||||
ColorAuto
|
||||
| ColorAlways
|
||||
| ColorNever
|
||||
deriving (Ord, Eq, Show)
|
||||
|
||||
-- Parser input and output
|
||||
data ParseSpec = ParseSpec {
|
||||
psFilename :: String,
|
||||
|
@ -81,6 +72,13 @@ data AnalysisResult = AnalysisResult {
|
|||
arComments :: [TokenComment]
|
||||
}
|
||||
|
||||
|
||||
-- Formatter options
|
||||
data FormatterOptions = FormatterOptions {
|
||||
foColorOption :: ColorOption
|
||||
}
|
||||
|
||||
|
||||
-- Supporting data types
|
||||
data Shell = Ksh | Sh | Bash | Dash deriving (Show, Eq)
|
||||
data ExecutionMode = Executed | Sourced deriving (Show, Eq)
|
||||
|
@ -99,6 +97,12 @@ data Comment = Comment Severity Code String deriving (Show, Eq)
|
|||
data PositionedComment = PositionedComment Position Comment deriving (Show, Eq)
|
||||
data TokenComment = TokenComment Id Comment deriving (Show, Eq)
|
||||
|
||||
data ColorOption =
|
||||
ColorAuto
|
||||
| ColorAlways
|
||||
| ColorNever
|
||||
deriving (Ord, Eq, Show)
|
||||
|
||||
-- For testing
|
||||
mockedSystemInterface :: [(String, String)] -> SystemInterface Identity
|
||||
mockedSystemInterface files = SystemInterface {
|
||||
|
|
|
@ -32,7 +32,7 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.
|
|||
|
||||
# OPTIONS
|
||||
|
||||
**-C**\ [*WHEN*],\ **--color**[=*WHEN*]
|
||||
**-C**[*WHEN*],\ **--color**[=*WHEN*]
|
||||
|
||||
: For TTY outut, enable colors *always*, *never* or *auto*. The default
|
||||
is *auto*. **--color** without an argument is equivalent to
|
||||
|
|
|
@ -60,13 +60,15 @@ instance Monoid Status where
|
|||
data Options = Options {
|
||||
checkSpec :: CheckSpec,
|
||||
externalSources :: Bool,
|
||||
color :: ColorOptions
|
||||
formatterOptions :: FormatterOptions
|
||||
}
|
||||
|
||||
defaultOptions = Options {
|
||||
checkSpec = emptyCheckSpec,
|
||||
externalSources = False,
|
||||
color = ColorAuto
|
||||
formatterOptions = FormatterOptions {
|
||||
foColorOption = ColorAuto
|
||||
}
|
||||
}
|
||||
|
||||
usageHeader = "Usage: shellcheck [OPTIONS...] FILES..."
|
||||
|
@ -96,12 +98,12 @@ parseArguments argv =
|
|||
printErr $ concat errors ++ "\n" ++ usageInfo usageHeader options
|
||||
throwError SyntaxFailure
|
||||
|
||||
formats :: Map.Map String (IO Formatter)
|
||||
formats = Map.fromList [
|
||||
formats :: FormatterOptions -> Map.Map String (IO Formatter)
|
||||
formats options = Map.fromList [
|
||||
("checkstyle", ShellCheck.Formatter.CheckStyle.format),
|
||||
("gcc", ShellCheck.Formatter.GCC.format),
|
||||
("json", ShellCheck.Formatter.JSON.format),
|
||||
("tty", ShellCheck.Formatter.TTY.format)
|
||||
("tty", ShellCheck.Formatter.TTY.format options)
|
||||
]
|
||||
|
||||
getOption [] _ = Nothing
|
||||
|
@ -157,12 +159,13 @@ process flags files = do
|
|||
options <- foldM (flip parseOption) defaultOptions flags
|
||||
verifyFiles files
|
||||
let format = fromMaybe "tty" $ getOption flags "format"
|
||||
let formatters = formats $ formatterOptions options
|
||||
formatter <-
|
||||
case Map.lookup format formats of
|
||||
case Map.lookup format formatters of
|
||||
Nothing -> do
|
||||
printErr $ "Unknown format " ++ format
|
||||
printErr "Supported formats:"
|
||||
mapM_ (printErr . write) $ Map.keys formats
|
||||
mapM_ (printErr . write) $ Map.keys formatters
|
||||
throwError SupportFailure
|
||||
where write s = " " ++ s
|
||||
Just f -> ExceptT $ fmap Right f
|
||||
|
@ -238,8 +241,8 @@ parseOption flag options =
|
|||
|
||||
Flag "color" color ->
|
||||
return options {
|
||||
checkSpec = (checkSpec options) {
|
||||
csColorOption = parseColorOption color
|
||||
formatterOptions = (formatterOptions options) {
|
||||
foColorOption = parseColorOption color
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue