Let annotator work in batch mode

This commit is contained in:
Alexander Kobjolke 2022-03-09 00:51:14 +01:00
parent 9da29e683a
commit 3c43cd7c5d

View file

@ -50,6 +50,7 @@ data Options = Options
, verbosity :: Verbosity
, showVersion :: Maybe ShowVersion
, showHelp :: Bool
, batchMode :: Bool
, contextLines :: Int
, onlyNewest :: Bool
, annotationFiles :: [FilePath]
@ -64,6 +65,7 @@ defaultOptions = Options
, verbosity = Silent
, showVersion = Nothing
, showHelp = False
, batchMode = False
, contextLines = 0
, onlyNewest = True
, annotationFiles = []
@ -88,6 +90,9 @@ options =
, Option ['h'] ["help"]
(NoArg (\opts -> opts { showHelp = True }))
"show usage information"
, Option ['b'] ["batch"]
(NoArg (\opts -> opts { batchMode = True }))
"run in batch mode, i.e. do not ask any questions"
, Option ['a'] ["all"]
(NoArg (\opts -> opts { onlyNewest = False}))
"handle all defects not just Newest"
@ -152,7 +157,7 @@ defaultMain = do
putStr $ usageInfo header options
exitWith ExitSuccess
automaticAnnotations <- rights . concat <$> mapM fromFile (annotationFiles opts)
automaticAnnotations <- rights . concat <$> (filterM fileExist (annotationFiles opts) >>= mapM fromFile)
let opts' = opts { autoAnnotations = automaticAnnotations }
@ -384,14 +389,15 @@ handleViolation content v@Violation{..} = do
, description
])
putStrLn (code))
choice <- getUserChoice v
case choice of
Abort -> liftIO $ exitSuccess
Annotate annotation -> pure $ Just (AnnotatedViolation v annotation indent)
Skip -> pure Nothing
Help -> handleViolation content v
if batchMode opts
then pure $ Nothing
else do
choice <- getUserChoice v
case choice of
Abort -> liftIO $ exitSuccess
Annotate annotation -> pure $ Just (AnnotatedViolation v annotation indent)
Skip -> pure Nothing
Help -> handleViolation content v
where
lookupAnnotation :: Rule -> [Annotation] -> Maybe Annotation
lookupAnnotation _ [] = Nothing