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